Solved

How to use Oracle indexes of a linked server?

Posted on 2004-04-16
7
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

717 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