刚做了两个delete 优化,时间从无耐心看到结果到27秒,效率提高很多。
这些delete操作,都涉及的在几个表之间的关联判断。
总结一下:
像之前多表update一样,被delete 的表,不要参与到where之后的子查询判断中,也就是不要使用关联的子查询,
而是子查询得到一个被删除表的主键,或者rowid,然后使用in子查询进行判断删除。
这样会快很多,一般形式我总结如下:
---低效关联delete:
Delete ta where exists(select 1 from tb where ta.c=tb.c);
---高效非关联delete:
Delete ta where ta.rowid in (select ta.rowid from ta,tb where ta.c=tb.c);
--merge方式:
Merge ta
Using(select ta.id from ta,tb where ta.c=tb.c) x
On (ta.id=x.id)
When matched then
Delete;
注明:从oracle10g开始,merge提供了delete功能:
相关事例我找了一个给大家:
http://duqiangatom.blog.163.com/blog/static/1150251820105621412471/
希望对大家有用!