Solved

How to use Oracle indexes of a linked server?

Posted on 2004-04-16
7
284 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
push and Pull replication 31 47
Star schema daily updates 2 35
UPDATE JOIN multiple tables 5 20
Trouble installing msi file with msiexe.exe 2 17
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

756 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