SQL Query takes long time to execute -Need Help in fine tune the query.

Query takes more time to Execute. Please suggest how to improve the execution timing.

e.remedy_login_id as LoginCTM,
e.person_id as personID_CTM,
e.instanceid as InstanceCTM,

select v.flag_change_end_user_emp_id_, v.asset_id_, v.modified_date, v.end_user_emp_id_ from (select flag_change_end_user_emp_id_, asset_id_, modified_date, end_user_emp_id_ from Aradmin.ams_ast_field_tracking@amsbase.itg.ti.com a
where not exists
(select 1 asset_id_ from owner.table1@EDB b
where a.asset_id_=b.asset_id_ and b.modified_date > a.modified_date )) v where v.modified_date > '1223855640' and v.flag_change_end_user_emp_id_= 0 order by v.asset_id_

) z
LEFT JOIN BASETAB y ON substr(z.asset_id_, 4) = substr(y.assetid, 4)
LEFT JOIN PEOPLETAB e ON z.end_user_emp_id_= e.remedy_login_id
LEFT JOIN ASTPEOPLETAB f ON substr(z.asset_id_, 4) = substr(f.asset_id_, 4)
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

1. You may want to consider making your derived table (z) a view
2. Do you have indexes on all the join fields (i.e. asset_id, emp_id, etc.)?
3. Have you tired looking at the execution plan and seeing what is taking the longest time?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hello also could you provide us the table row count for each table it will help to point where it is slow

I never used oracle before, could you tell me what the table name Aradmin.ams_ast_field_tracking@amsbase.itg.ti.com  mean, is it a kind of linked server ? if yes do you have good network performance with it ?

Also do not forget that you use three nested query, if it is possible try to change those to use simple join it will improve the performance
What the above posters said - execution plan would be a great help in identifying the bottlenecks.

Also, just looking at the query, it looks like the various asset_id fields you use in your join/where criterias are of string (varchar) type, correct? Using string types as criterias are generelly very "expensive" performance-wise. Especially if they are not indexed, if the data set is large and/or if you're using functions like substr in the criteria.

Also, as was already suggested, try to modify your query to remove the nesting. Unless not possible, I generally advice to join rather than nest queries.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.