Analyzing Linked-Server Queries

SQL Server Profiler can reveal only what's executing on SQL Server. But linked-server queries also execute on the Oracle server, so to fully analyze an Oracle linked-server query, you must use Oracle's SQL Trace facility. You can enable SQL Trace at either the session level or the instance level. You enable SQL Trace for the instance by adding the following lines to the Oracle parameter file, init.ora:

timed_statistics = true
sql_trace = true

Instance-level tracing slows the server but ensures that you won't miss anything. You can identify Oracle trace files, which reside in the UDUMP folder specified in the init.ora file, by their .trc extension.

When you issue a linked-server query, the OLE DB provider causes the server to execute an extra query, which obtains metadata from the Oracle data dictionary. SQL Server needs the Oracle metadata to complete the query resolution on the SQL Server side. For example, let's analyze the following query

SELECT * FROM oradb..SCOTT.BIGTAB WHERE orderid = 10248

where BIGTAB is an unindexed multimillion-row table. Two queries were executed, as Figure A's excerpt from the trace file shows.

You can use the Oracle utility TKPROF to reformat a trace file into a more readable format. However, finding the relevant data in the trace file is easy. In the trace file excerpt, look for tim, which represents the elapsed time, measured in hundredths of a second. Note that although only one query was submitted from the Query Analyzer, two queries were executed on the Oracle server. Although the first query's execution plan shows that the server executed a full table scan, this fact is misleading. The query doesn't have a FETCH statement and doesn't return data. Subtracting the first query's starting tim value from the second query's starting tim value, you can see that the elapsed time for the first query is only 0.01 second. A true table scan against a table this size would take much longer.

Although Profiler offers an Oracle trace template, it can only provide limited details such as when a query starts and finishes. Use Oracle's trace facility if you need to analyze Oracle linked-server query performance problems.

Discuss this Article 2

Anonymous User (not verified)
on Feb 23, 2005
I follow the instructions for calling a SP from a triger . What is strange is that i need to execute twice the update command from SQL Server to ber excuted ! Do you have any idea !!! Regards
Anonymous User (not verified)
on Oct 12, 2004
Excellant one to understanding the connecting method of oracle database through SQL server using linked server

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottOur Experts will show you:
• Common SQL Server
Problems
• Best Practices for T-SQL
• SQL Server Integration
Services
• Database Development

Come See Michael Otey & Tim Ford in Person!

Early Registration Now Open

From the Blogs
May 21, 2013
blog

A Common Misconception about MAXDOP

Out of the box, SQL Server is (and has been) able to take advantage of multiple processors/cores without any effort on behalf of administrators....More
May 9, 2013
blog

My ISO 8601-Compliant Signature 2

My family recently just "officially" announced that we're in the process of adopting a child from South Africa. We're quite excited, of course, but there's a ton of paperwork to do—along with the need for gobs of signatures....More
May 8, 2013
blog

Use SSIS for ETL from Hadoop

In this blog post, Mark Kromer walks you through using SSIS as a way to use ETL techniques using Microsoft's Hadoop on Windows (HDInsight) as a source using Hive connectors...More
SQL Server Pro Forums

Get answers to questions, share tips, and engage with the SQL Server community in our Forums.