简体   繁体   English

我如何提高此oracle sql删除查询的性能?

[英]how can i improve the performance of this oracle sql delete query?

I got to delete some unwanted rows from a table based on the result of a select query from another table 我必须根据另一个表中的选择查询结果从表中删除一些不需要的行

DELETE /*+ parallels(fe) */  FROM fact_x fe
WHERE fe.key NOT IN(
  SELECT DISTINCT di.key
  FROM dim_x di
  JOIN fact_y fa
  ON fa.code         = di.code
  WHERE fa.code_type = 'ABC'
 );

The inner select query returns 77 rows and executes in few milliseconds. 内部选择查询返回77行,并在几毫秒内执行。 but the outer delete query runs forever(for more than 8 hrs). 但外部删除查询将永久运行(超过8小时)。 I tried to count how many rows got to be deleted by converting the delete to select count(1) and its around 66.4 million fact_x rows out of total 66.8 million rows. 我试图通过将delete转换为select count(1)及其总数6680万行中的约6640万fact_x行来计算要删除多少行。 I am not trying to truncate though. 我不是想截断。 I need to retain remaining rows. 我需要保留剩余的行。

Is there any other way to achieve this? 还有其他方法可以做到这一点吗? will deleting this by running a pl/sql cursor will work better? 将通过运行pl / sql游标删除它会更好?

Would it not make more sense just to insert the rows you want to keep into another table, then drop the existing table? 仅将要保留的行插入另一个表,然后删除现有表,是否更有意义? Even if there are FKs to disable/recreate/etc. 即使有FK禁用/重新创建/等。 it almost certain to be faster. 几乎可以肯定会更快。

Could you add a "toBeDeleted" column? 您可以添加“ toBeDeleted”列吗? The query to set that wouldn't need that "NOT IN" construction. 设置不需要“ NOT IN”构造的查询。 Deleting the marked rows should also be "simple". 删除标记的行也应该是“简单的”。

Then again, deleting 99,4% of the 67 million rows will take some time. 然后,再次删除6700万行中的99.4%将需要一些时间。

Try /*+ parallel(fe) */. 尝试/ * + parallel(fe)* /。 No "S". 没有“ S”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM