Delete statement was very slow in Oracle

前端 未结 4 2238
爱一瞬间的悲伤
爱一瞬间的悲伤 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:17

    There can be many reasons:

    • Server load (unlikely because the SELECT is fast)
    • Triggers (see here how to list them for a table).
    • Foreign keys (List of foreign keys and the tables they reference)
    • A lot of data in each row (LOBs, many columns).
    • Someone is locking rows in the table that you'd like to delete (or the whole table). See this blog post how to list locks. This discussion might also help.

    If the foreign keys are the problem, the usual solution is to add indexes on the foreign column: For each delete, Oracle needs to check whether this would violate a foreign key relation.

提交回复
热议问题