Query taking very long time to run

My following query is taking very long time to run.Please suggest the ways to tune this query.
Key1 and key2 are indexed columns.tab2 is a partitioned table.tab1 is in other schema.

Select

 CREDITORS_MEETING_STATUS_CD,

TRANSFER,

FLG,


from tab1@mdm.com  a,

     tab2 b

where a.key1=b.key2

and program_id=1;

It takes hours to run.
Thanks in advance.

 

pooja74Asked:
Who is Participating?
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.

morphmanCommented:
Ok, you are using a database link to retreive your data. First you must check if the query still takes ages to run on the source system.

Log into mdm.com database, and execute the query withotu the @mdm.com part. If its fast, you are out of luck, as it means yoru database link is slow normally because of slow network connections.

If it still runs slow, there can eb many things that make it run slow.

1. How many rows are in tab1@mdm.com
2. How many rows are in tab2
3. Is program_id indexed
4. What fields are tab2 partitioned on.

Run an explain plan, if there are any types of nested loops here, that is very bad over a network link, as every row will be read on 1 database, and then the other database will be checked over the network link. You need to USE_HASH the remote table if possible. This will only incur 1 network round trip (or just a few) compared to one per row for nested loop operations.

ie.

select /*+ USE_HASH(a) */
CREDITORS_MEETING_STATUS_CD,

TRANSFER,

FLG,


from tab1@mdm.com  a,

     tab2 b

where a.key1=b.key2

and program_id=1;
0

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
morphmanCommented:
Another alternative would be to create a local copy of tab1@mdm.com before running this query (via materialized views or any other replication technique), and then you can query 2 tables on the same database which will obviosly be much quicker.
0
tomcat75Commented:
For optimizing this query you can also try using the driving_site hint :

ex
"SELECT /*+DRIVING_SITE(dept)*/ * FROM emp, dept@rsite
 WHERE emp.deptno = dept.deptno;"

for oracle to execute the query on the site where you have the largest table.

HTH




0
Murali MurugesanFull stack Java developerCommented:
Hi,
Create a Synonym for the table in other schema.
Y cant u use a materialized view for this purpose  i hope that would help u.
Normally for referring another table in a different schema it may take some time.
Just execute the explain plan for ur query and get to know where it takes more time.

-Murali*
0
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
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.