Solved

How to use Oracle indexes of a linked server?

Posted on 2004-04-16
7
282 Views
Last Modified: 2012-06-21
I have create a linked table to an Oracle server in SQL Server Enterprise Manager.  It connects fine. But the table has 18 millions of rows. So if I query from SQL Server, it takes a lot of time to do that. Is there any way to use or retrieve the indexes of the Oracle table?

In Enterprise Manager -> Linked Servers I see that I have retrieved only tables and views, but no indexes.

I refer to the Oracle table in this way:
select * from LINKEDSERVERNAME..OWNER.TABLE where field01='xx' and field02='yy'

Thanks!

0
Comment
Question by:Cali_Salas
  • 4
  • 3
7 Comments
 
LVL 34

Expert Comment

by:arbert
ID: 10843953
You're kind of at the mercy of the OLEDB driver.  SQL Server tries to decide what it can "safely" pass in a query to the remote database.  If it doesn't think it can pass criteria, it will scan all records and apply the "criteria" on the entire resultset that is returned.

Just for giggles, will you try openquery to see if your performance is better?

select * from openquery(linkedservername,'select * from owner.table where field01=xx and field02=yy')

Brett
0
 

Author Comment

by:Cali_Salas
ID: 10844074
Thnaks, is there any way to use OPENQUERY and " ?
I tried to query:

select * from openquery(linkedservername,'select * from owner.table where field01=xx')

[OLE/DB provider returned message: ORA-00904: "xx": invalid identifier]

field01 is a char field

0
 
LVL 34

Accepted Solution

by:
arbert earned 125 total points
ID: 10844147
Sorry, you just double up the single quotes:

select * from openquery(linkedservername,'select * from owner.table where field01=''xx''')
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:Cali_Salas
ID: 10844169
Ok, the syntax is:
select * from openquery(LINKEDSERVERNAME,'select * from OWNER.TABLE') where field01='xx'

But nothing changes, it takes a lot of time, I just cancel the query.

So... Do we have to think that Linked Servers cannot use indexes and are just a waste of time?
0
 
LVL 34

Expert Comment

by:arbert
ID: 10844201
NO...You just did the same thing that was happening above--you need to include the criteria on the inner select....

Linked servers will use indexes if the criteria is passed to the database in the first place...
0
 

Author Comment

by:Cali_Salas
ID: 10844373
Thanks, arbert, it works well.
0
 
LVL 34

Expert Comment

by:arbert
ID: 10844402
That basically issues a "pass-thru" query to the linked server and passes the statement "as-is".  Like I said before, if you just use the linked server in a query with the 4dot naming convention, SQL Server may or may not pass the criteria to the other server--just depends on if SQL thinks it can pass good criteria or not.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how the fundamental information of how to create a table.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question