Solved

Insert to different schema - Optimization

Posted on 2011-03-22
3
578 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 77

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Repeat query 13 74
best datatype for oracle table email creation 8 78
Migration from sql server to oracle (IF then else condition ) 13 45
Password_rules_securitty.. 12 35
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
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 shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
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…

726 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