0

I need to move data from an Oracle database to SQL Server.

If I run this very simple directly on the database, I get my results in < 1 second (returns 30K out of 250m rows):

select * 
From my_table             
where my_date = to_date('2024-09-17', 'YYYY-MM-DD') 

But if it takes 1.5 minutes to run the exact same query using openquery / linked server

select * 
FROM OPENQUERY(ORACLE_SERVER, 'select *
                               from my_table             
                               where my_date = to_date(''17-09-2024'', ''DD-MM-YYYY'')') A

I tried with and without the to_date with no material changes.

I'm expecting the linked server to be slower, but not 100x.

Any idea where that could be coming from?

Thanks in advance

1
  • 1
    Are you sure you are measuring the same things? When you run the query on the database you may be measuring the time to return the first row. When you run the query on the linked server, (apart from also having network transfer time) you may be measuring the time to return the last row. Commented Sep 19, 2024 at 20:23

1 Answer 1

1

There are 3 ways to execute query against a Linked Server in T-SQL:

  1. Calling with four-part naming convention
  2. Using OpenQuery and OpenRowSet
  3. EXECUTE() AT [LinkedServer]

For the reference: SQL Server: Execute At LinkedServer

Please try the fastest method #3 as follows below. It guaranties that the WHERE clause will be applied on the Oracle db side.

T-SQL

EXECUTE('select * from my_table             
    where my_date = to_date(''17-09-2024'', ''DD-MM-YYYY'')') AT [ORACLE_SERVER];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.