Skip to Main Content
  • Questions
  • Differance performance when execute a single insert with append hint via dblink and put it into procedure

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Ngan.

Asked: June 12, 2021 - 10:49 am UTC

Last updated: July 06, 2021 - 1:49 am UTC

Version: 11g

Viewed 1000+ times

You Asked

Hi Tom,
I have a problem following
I have 2 database at 2 different site and my job is transfer user a scheduler job at site B, pulling data from site A via dblink_b2a. about 14m records/day
when I execute single statement:
    insert /*+ append */ into table_b 
      from select * from table_b@dblink_b2a
     where condition >= v_start_time
       and condition <  v_end_time
    ;

=> duration time about 15-20 minutes

But when I put it in procedure and run scheduler job, it ran very slowly ~15 hours and not completed yet.
My sample procedure:
create or replace procedure transfer_Data 
as 
    v_start_time date := trunc(sysdate - 1);
    v_end_time   date := trunc(sysdate);
begin 
    insert /*+ append */ into table_b 
      from select * from table_b@dblink_b2a
     where condition >= v_start_time
       and condition <  v_end_time
    ;
end; 


Please tell me reasons and advises for this case
Hope your responding as soon as you can
Thank you and best regards!

and Connor said...

How did you run

insert /*+ append */ into table_b 
      from select * from table_b@dblink_b2a
     where condition >= v_start_time
       and condition <  v_end_time    ;


directly in SQL? Did you use literal values for the start and end times? That is the most likely difference.

But since PLSQL will uppercase any SQL, you should have two SQL's in your library cache

- lower case one - the one you ran from SQL
- upper case one - the one you ran from PLSQL

For each one, get the SQL_ID and then get the execution plan using DBMS_XPLAN.

That will tell you if the plans were different (which could easily explain the difference in performance)




Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Ngan Do, July 04, 2021 - 2:49 am UTC

HI sir,
I tested follow your suggestion, and exactly two execution plans are different.
Thank you very much for you support!
Connor McDonald
July 06, 2021 - 1:49 am UTC

glad we could help

More to Explore

Performance

Get all the information about database performance in the Database Performance guide.