SQL Server access Oracle Query performance Problem Resolution

Source: Internet
Author: User
Tags oracle database

1. The question

The system has a module that needs to query the data in the Oracle database. It is now implemented by establishing a linked server.

SQL Server access Oracle implementation can refer to this article http://www.cnblogs.com/gnielee/archive/2010/09/07/access-oracle-from-sqlserver.html

The current query statement is a simple query with a where condition, similar to the following:

Select*from Linked_name. Account_name. table_name WHERE COLUMN1=SID;

The problem is that the query is very slow and the foreground report times out. So prepare to upgrade the performance of the query

2. Analysis

First, determine if the table for remote Oracle has an index on the filtered field. After confirmation, there is an index.

The execution plan for executing statements is then viewed in the SSMs client, as follows:

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/SQLServer/

As you can see from the execution plan, the process is not what it was supposed to be, and it was assumed that SQL Server would submit the entire query to the Oracle servers for execution. Instead of a where condition when the remote query is actually in place, the result is returned locally, and the filter is performed locally (there is a filter)

This speed is certainly very slow, because the query does not use the index lookup, the need to transfer all the remote data to the local before performing filtering, equivalent to full table scan, and more network transmission time.

3. Address

In fact, the performance problem can be solved by submitting a query statement with a WHERE condition to the Oracle server to execute the remote query.

However, the problem is that OPENQUERY does not support parameters. See Microsoft Msdnhttp://technet.microsoft.com/zh-cn/library/ms188427.aspx

But fortunately we can find a way to implement the pass query parameters by splicing dynamic SQL.

OpenQuery use parameters can refer to this article: http://www.cnblogs.com/Dannier/archive/2011/09/21/openquery.html

When optimized in this way, the execution plan becomes as follows: you can see that the actual number of rows returned is very small.

The query speed is increased significantly, from the original foreground timeout to the current millisecond level.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.