Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Insert to different schema - Optimization

Posted on 2011-03-22
3
Medium Priority
?
585 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 78

Accepted Solution

by:
slightwv (䄆 Netminder) earned 1000 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 600 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 400 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses

926 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