Delete statement was very slow in Oracle

前端 未结 4 2227
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-20 17:15

I have a table with about 100k records and I want to delete some rows, The problem is that the DELETE statement is running very slowly - it didn\'t finish in 30 min

4条回答
  •  梦谈多话
    2021-02-20 18:13

    To delete means to change the table's content. And this means, that after each deleted row all indexes must be updated and all foreign-key references must be checked. This can take a very long time!

    Maybe this helps:

    Make a copy of that table without any references, triggers and additional indexes. Then do this:

    insert into new_table (field1, field2, ...) values (
        select field1, field2, ...
        from daily_au_by_service_summary 
        where summary_ts < to_date('09-04-2012','dd-mm-yyyy') 
    );
    

    If the fields in the tabels are defined in identical order, this might work too:

    insert into new_table values (
        select *
        from daily_au_by_service_summary 
        where summary_ts < to_date('09-04-2012','dd-mm-yyyy') 
    );
    

    After that:

    truncate daily_au_by_service_summary
    

    and then:

    insert into daily_au_by_service_summary (field1, field2, ...) values (
        select field1, field2, ...
        from new_table; 
    );
    

    New Table is not needed any longer:

    drop new_table;
    

提交回复
热议问题