Tunning of query

Tags:
Oracle
insert into tblsap_history(select * from tblsap ts where ( (ts.css_database,ts.sap) in (select SUBSTR(source_account, 1, 2),SUBSTR(source_account, 3, 18) from ds_account a where a.source_system = 1 and ts.taig='ISY002' and (sysdate-required_by) >= 180 ) ) union all select * from tblsap ts where ( (ts.css_database,ts.sap) not in (select SUBSTR(source_account, 1, 2),SUBSTR(source_account, 3, 18) from ds_account a where a.source_system = 1 and (sysdate-required_by) >= 180 ) ) ) ; in this case both the 1st and 2nd select queries we are using same columns to select field, and also condtion (sysdate-required_by) >= 180 same is used in both the queries. how we minimize this queries and how to optimize this queries. in 1st select we use 'in' condition but in 2nd 'Not in' used, in 1st select additionaly need to check one condition taig=''. can you please reply me as soon as possible..

Answer Wiki

Thanks. We'll let you know when a new response is added.

I haven’t done sql for a while but i think that maybe you can try :

insert into tblsap_history
(
select *
from tblsap ts
where
(
(ts.css_database,ts.sap) in
(
select SUBSTR(source_account, 1, 2),SUBSTR(source_account, 3, 18)
from ds_account a
where a.source_system = 1
and ts.taig=’ISY002′
and (sysdate-required_by) >= 180
)
or
(ts.css_database,ts.sap) not in
(
select SUBSTR(source_account, 1, 2),SUBSTR(source_account, 3, 18)
from ds_account a
where a.source_system = 1
and (sysdate-required_by) >= 180
)
)
);

You could also try to index (css_database,sap) columns of tblsap table
and/or (source_account) column of ds_account table

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: