SQL Server accesses Oracle to query performance

Source: Internet
Author: User
1. The problem system has a module that needs to query data in the Oracle database. Currently, this is achieved by creating a linked server. The current query statement of limit is a simple

1. The problem system has a module that needs to query data in the Oracle database. Currently, this is achieved by creating 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 current query statement is a simple with wh

1. Problem

The system has a module to query data in the Oracle database. Currently, this is achieved by creating 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 statement with the where condition, similar to the following:

  

SELECT * FROM LINKED_NAME..ACCOUNT_NAME.TABLE_NAME WHERE COLUMN1=SID;

The problem is that the query speed is very slow and the frontend reports a timeout. Therefore, we are prepared to improve the query performance.

2. Analysis

First, check whether the remote Oracle table has an index on the filter field. It has been confirmed that an index exists.

Then, the execution plan of the statement is viewed in the SSMS client, as follows:

  

From the execution plan, we can see that the process is not as imagined. I thought that SQLServer would submit the entire query to the Oracle server for execution. In actual remote query, the where condition is not added, but the result is returned to the local machine and filtered locally (with a filter)

This speed will certainly be very slow, because the query does not use index search, you need to transmit all the remote data to the local machine before filtering, equivalent to full table scan, more time for network transmission.

3. Solution

In fact, as long as the query statement with the where condition can be submitted to the Oracle server for remote query, the performance problem can be solved.

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

  

However, we can find another way to pass query parameters by splicing dynamic SQL statements.

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

After optimization, the execution plan becomes as follows: You can see that the number of actually returned rows is small.

  

The query speed is significantly improved, from the original frontend timeout to the current millisecond level.

Little proud ^ _ ^, welcome to make a brick. If you have other methods, please share them. Thank you!

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.