我有以下查詢。由於其中的子查詢會降低性能。我嘗試了很多添加聯接而不是子查詢。但徒勞無益。任何人都可以告訴我如何使用JOIN重寫此查詢?需要調整此sql查詢以提高性能
update Table_1
set status = 'Status_2'
where status ='status_1' and (col_1, col_2, col_3, nvl(col_4,0), col_5) in (
select col_1, col_2, col_3, nvl(col_4,0), col_5 from Table_2 where status ='Status_0');
請參閱下面的SELECT * FROM table(DBMS_XPLAN.Display);
Plan hash value: 1290346170
------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------------
| 0 | UPDATE STATEMENT | | 1 | 376 | 456 (3)| 00:00:06 |
| 1 | UPDATE | Table_1 | | | | |
| 2 | NESTED LOOPS | | | | | |
| 3 | NESTED LOOPS | | 1 | 376 | 456 (3)| 00:00:06 |
| 4 | SORT UNIQUE | | 1 | 316 | 454 (3)| 00:00:06 |
|* 5 | TABLE ACCESS FULL | Table_2 | 1 | 316 | 454 (3)| 00:00:06 |
|* 6 | INDEX RANGE SCAN | Table1_INDEX | 1 | | 1 (0)| 00:00:01 |
|* 7 | TABLE ACCESS BY INDEX ROWID| Table_1 | 1 | 60 | 1 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------------`enter code here`
請運行'EXPLAIN PLAN FOR your_query',然後'SELECT * FROM table(DBMS_XPLAN.Display)',然後複製它的輸出並粘貼到問題中。 – krokodilko
@kordirko,請看看結果。 – Msn
@Msn估計的時間只有6秒,非常快。查詢所花費的實際時間是多少? –