Solved

How to use Oracle indexes of a linked server?

Posted on 2004-04-16
7
280 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now