Solved

Insert to different schema - Optimization

Posted on 2011-03-22
3
573 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 73

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.

Join & Write a Comment

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now