从表调整中删除记录

时间:2019-12-03 14:01:35

标签: oracle sql-tuning

我试图根据不同的标准从表中删除一些记录。虽然,代码运行良好,但是执行时间却超出了预期。

请建议是否还有其他方法可以重写以下查询。

查询:

DELETE FROM cm_rg_reg rg
WHERE ROWID IN (SELECT ROWID FROM
                                (SELECT ROW_NUMBER() OVER (PARTITION BY cr_id, tr_type, rg_id, rg_state, rg_eff_dt ORDER BY RG_SEQ_NO DESC) AS LI
                                            FROM cm_rg_reg rg
                                            WHERE tr_type='LI'  
                                            AND rg_state NOT IN ('MI') 
                                            AND rg_term_dt IN ('31-DEC-9999' , '01-JAN-1753' )
                                            AND NOT EXISTS (SELECT 1 FROM cb_prov_pass_xwalk xwalk
                                                            INNER JOIN cm_pr_prov pr
                                                            ON SUBSTR(pr.pr_id,1,9) = xwalk.mpin
                                                            AND pr.mctn_id = xwalk.tax_id
                                                            WHERE rg.cr_id = pr.cr_id)
                                        )
                        WHERE LI > 1); 

0 个答案:

没有答案