Solved

Insert to different schema - Optimization

Posted on 2011-03-22
3
577 Views
Last Modified: 2012-06-22
I have a simple insert statement with in my Stored Procedure:
Insert into Schema2.T1
Select * from Schema1.T1

There are 3 million rows and Toad shows cost as 17939.
How do I optimize this and quicken this load?

0
Comment
Question by:codemonkey2480
3 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 250 total points
ID: 35193278
Use the APPEND hint to insert above the high water mark:

Insert /*+ APPEND */ into Schema2.T1
Select * from Schema1.T1



or

PL/SQL cursor loop with a commit every X rows to reduce undo?

declare
   counter number := 1;
begin
for i in (select * from Schema1.T1) loop
    insert into Schema2.T1(col1, col2) values(i.col1, i.col2);
    if mod(counter,1000)=0 then
         commit;
    end if;
    counter := counter+1;
end loop;
end;
/
0
 
LVL 74

Assisted Solution

by:sdstuber
sdstuber earned 150 total points
ID: 35194074
ignore COST

using the append hint is the fastest way to do your insert.

I wouldn't try using a loop, that simply adds extra steps and since it's an insert, the undo should be minimal.

If you have triggers, constraints or indexes on the target table, those will all make the insert slower.

You might not be able to disable the triggers, but possibly you could drop the indexes and disable the constraints.
Then recreate the indexes when done and reenable the constraints.

If you follow those, make sure nobody else is going to touch that table while you are inserting or their access will be slow and could create corrupt data while the constraints are off

0
 

Assisted Solution

by:josiethejewel
josiethejewel earned 100 total points
ID: 35197089
I would use the append hint and disable your indexes without dropping them. Disabling the indexes set them unusable so you will have to set your session to ignore unusable indexes. Once your data is inserted you can rebuild your indexes and everything will work fine. Every time oracle insert a row without the index disabled it has to rewrite the index. I did this for our database and took our loads( about 4 Million records) from 24 hours to about 2 hours.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question