ITPUB??ì3
2010数据库技术大会
ITPUB论坛 » Oracle数据库管理 » 删除太慢了,请问如何加快?


您有 1 条公共消息
  • 来自: 公共消息 标题: 3-5月ITPUB数据库 ... 内容: ITPUB与3月和5月分别安排了Oracle 11g DBA和Oracle性能优化培训,以及 ...

    标题: 删除太慢了,请问如何加快?
    离线 coohoo
    Victor


    精华贴数 0
    个人空间 0
    技术积分 1494 (1416)
    社区积分 8 (14880)
    注册日期 2005-1-31
    论坛徽章:3
    授权会员ITPUB新首页上线纪念徽章    
          

    发表于 2006-6-21 15:10 
    删除太慢了,请问如何加快?

    删除重复记录前,先查询了一下要删除的有多少行:
    select count(*)
      from tab1 a
    where a.rowid < (select max(b.rowid)
                        from tab2 b
                       where a.col1 = b.col1
                         and a.col2 = b.col2);

    查询的结果有12万条记录,然后将select count(*)改为delete后开始执行…………4个小时了,现在还没执行完。
    有什么办法能加快吗?


    __________________
    my blog : http://coohoo.itpub.net/
    只看该作者    顶部
    离线 blue_prince
    永远的巴乔


    精华贴数 23
    个人空间 0
    技术积分 18935 (68)
    社区积分 6384 (308)
    注册日期 2003-10-15
    论坛徽章:101
    现任管理团队成员2010年世界杯参赛球队:智利2010新春纪念徽章2010年世界杯参赛球队:意大利祖国60周年纪念徽章ITPUB8周年纪念徽章
          

    发表于 2006-6-21 15:18 
    用分析函数,参考:
    PHP code:


    删除重复数据的一种高效的方法

    发表人
    :yaanzy 发表时间2005年二月18日13:57

    表demo是重复拷贝自dba_objects,有88万左右,不重复的是27323,没有索引

    方法一:delete from demo a where a
    .rowid <> (select max(rowidfrom demo b where

                                                                          b
    .object_id=a.object_id);

                
    耗时:几个小时以上

    方法二: delete from demo where rowid in 

                  
    (select rid from 

                              
    (select rowid rid,row_number() over(partition by object_id order by rowidrn

                                 from demo
    )

                   
    where rn <> );

       
    耗时:30秒

    方法三: create table demo2 
    as 

                  
    select object_id,owner... from

                           
    (select demo.*,row_number() over(partition by object_id order by rowidrn from demo)

                             
    where rn 1;

                  
    truncate table demoinsert into demo select from demo2drop table demo2;

    共耗时: 10秒,适合大数据量的情况,产生更少回滚量;



    ..




    __________________
    淘宝DBA团队Blog        我的Blog

    We are what we repeatedly do. Excellence, then, is not an act, but a habit.——Aristotle

    淘宝网2010招聘:Oracle、MySQL DBA,数据仓库开发和Hadoop开发
    只看该作者    顶部
    离线 blue_prince
    永远的巴乔


    精华贴数 23
    个人空间 0
    技术积分 18935 (68)
    社区积分 6384 (308)
    注册日期 2003-10-15
    论坛徽章:101
    现任管理团队成员2010年世界杯参赛球队:智利2010新春纪念徽章2010年世界杯参赛球队:意大利祖国60周年纪念徽章ITPUB8周年纪念徽章
          

    发表于 2006-6-21 15:18 
    建议用方法二


    __________________
    淘宝DBA团队Blog        我的Blog

    We are what we repeatedly do. Excellence, then, is not an act, but a habit.——Aristotle

    淘宝网2010招聘:Oracle、MySQL DBA,数据仓库开发和Hadoop开发
    只看该作者    顶部
    离线 coohoo
    Victor


    精华贴数 0
    个人空间 0
    技术积分 1494 (1416)
    社区积分 8 (14880)
    注册日期 2005-1-31
    论坛徽章:3
    授权会员ITPUB新首页上线纪念徽章    
          

    发表于 2006-6-21 15:37 
    谢谢~!我刚搜了一下,发现还有种办法:

    delete cz where (c1,c10) in (select c1,c10 from cz group by c1,c10 having count(*)>1) and rowid not in
    (select min(rowid) from cz group by c1,c10 having count(*)>1);


    __________________
    my blog : http://coohoo.itpub.net/
    只看该作者    顶部
    离线 rchsh
    高级会员


    精华贴数 0
    个人空间 0
    技术积分 10615 (143)
    社区积分 325 (2226)
    注册日期 2001-10-25
    论坛徽章:26
    ITPUB元老会员2006贡献徽章授权会员生肖徽章2007版:鸡生肖徽章2007版:鼠生肖徽章:狗
    生肖徽章:狗生肖徽章:兔生肖徽章:兔生肖徽章:兔生肖徽章:兔生肖徽章:兔

    发表于 2006-6-21 15:50 


    QUOTE:
    最初由 coohoo 发布
    谢谢~!我刚搜了一下,发现还有种办法:

    delete cz where (c1,c10) in (select c1,c10 from cz group by c1,c10 having count(*)>1) and rowid not in
    (select min(rowid) from cz group by c1,c10 having count(*)>1);


    这些方法效率都是很低的
    建议还是使用oracle 的分析函数比较快一点的


    __________________
    删除昨天的烦劳 确定今天的快乐设置明天的幸福 取消世间的仇恨复制醉人的风景 打印美丽的笑容
    只看该作者    顶部
    离线 Silentman
    老会员



    精华贴数 0
    个人空间 0
    技术积分 1134 (1960)
    社区积分 2 (29346)
    注册日期 2002-6-20
    论坛徽章:4
    ITPUB元老生肖徽章2007版:鼠ITPUB新首页上线纪念徽章   
          

    发表于 2006-6-21 16:04 
    要考虑删除的重复记录占总记录数的比例。


    __________________
    ================--- 好好学习,天天向上---================
    只看该作者    顶部
    离线 coohoo
    Victor


    精华贴数 0
    个人空间 0
    技术积分 1494 (1416)
    社区积分 8 (14880)
    注册日期 2005-1-31
    论坛徽章:3
    授权会员ITPUB新首页上线纪念徽章    
          

    发表于 2006-6-21 16:54 
    方法二: delete from demo where rowid in
                  (select rid from
                              (select rowid rid,row_number() over(partition by object_id order by rowid) rn
                                 from demo)
                   where rn <> 1 );
    对于此方法,如果判断两个字段是否重复,我这样写:
    delete from demo where rowid in
                  (select rid from
                              (select rowid rid,row_number() over(partition by object_id,object_id2 order by rowid) rn
                                 from demo)
                   where rn <> 1 );
    就是增加了第2个字段object_id2,但发现结果不对。应该怎么写?


    __________________
    my blog : http://coohoo.itpub.net/
    只看该作者    顶部
    离线 hotiice
    版主


    精华贴数 10
    个人空间 0
    技术积分 18451 (71)
    社区积分 1830 (811)
    注册日期 2004-9-9
    论坛徽章:33
    现任管理团队成员ITPUB长老会成员会员2007贡献徽章铁扇公主2010新春纪念徽章2010年世界杯参赛球队:日本
    2010新春纪念徽章祖国60周年纪念徽章生肖徽章2007版:牛生肖徽章2007版:虎生肖徽章2007版:羊数据库板块每日发贴之星

    发表于 2006-6-21 21:46 
    oracle的删除和更新操作本来就是很慢的,没有更好的办法,如果你预先分区还好一些


    __________________
    ①②⑧

    只看该作者    顶部
    离线 dba_mx
    珍惜健康 珍惜幸福



    精华贴数 0
    个人空间 0
    技术积分 2270 (858)
    社区积分 11 (12484)
    注册日期 2004-3-15
    论坛徽章:3
    会员2007贡献徽章ITPUB新首页上线纪念徽章数据库板块每日发贴之星   
          

    发表于 2006-6-22 11:02 
    如果没有大的影响,建议 CTAS


    只看该作者    顶部
    离线 Talmud
    Lighten Up


    精华贴数 0
    个人空间 0
    技术积分 1548 (1350)
    社区积分 60 (5507)
    注册日期 2006-3-5
    论坛徽章:2
    会员2007贡献徽章授权会员    
          

    发表于 2006-6-22 11:42 
    没有哪种是最优的,
    根据数据(分布,多少等等)情况,上面几种方式会用不一样的表现。


    __________________
    A system no faster than its worst bottleneck.不知道的总比知道的要多得多。
    只看该作者    顶部
     
        

    相关内容


    CopyRight 1999-2006 itpub.net All Right Reserved.
    北京皓辰网域网络信息技术有限公司. 版权所有
    E-mail:Webmaster@itpub.net
    网站律师 隐私政策 知识产权声明
    京ICP证:060528号 联系我们