tags:

views:

4266

answers:

6

I am writing a data conversion in PL/SQL that processes data and loads it into a table. According to the PL/SQL Profiler, one of the slowest parts of the conversion is the actual insert into the target table. The table has a single index.

To prepare the data for load, I populate a variable using the rowtype of the table, then insert it into the table like this:

insert into mytable values r_myRow;

It seems that I could gain performance by doing the following:

  • Turn logging off during the insert
  • Insert multiple records at once

Are these methods advisable? If so, what is the syntax?

A: 

Drop the index, then insert the rows, then re-create the index.

MusiGenesis
Using a bulk insetr methodology will mitigate the effect of having the index on there though.
David Aldridge
A: 

Check this link http://www.dba-oracle.com/t_optimize_insert_sql_performance.htm

  1. main points to consider for your case is to use Append hint as this will directly append into the table instead of using freelist. If you can afford to turn off logging than use append with nologging hint to do it
  2. Use a bulk insert instead instead of iterating in PL/SQL
  3. Use sqlloaded to load the data directly into the table if you are getting data from a file feed
Kalpesh Patel
+3  A: 

Regular insert statements are the slowest way to get data in a table and not meant for bulk inserts. The following article references a lot of different techniques for improving performance: http://www.dba-oracle.com/oracle_tips_data_load.htm

Joeri Sebrechts
+1  A: 

If dropping the index doesn't speed things up enough, you need the Oracle SQL*Loader:

http://www.oracle.com/technology/products/database/utilities/htdocs/sql_loader_overview.html

MusiGenesis
You can still use the same mechanism to optimise the load as sql*loader uses without resorting to the command line tool.
David Aldridge
+9  A: 

It's much better to insert a few hundred rows at a time, using PL/SQL tables and FORALL to bind into insert statement. For details on this see here.

Also be careful with how you construct the PL/SQL tables. If at all possible, prefer to instead do all your transforms directly in SQL using "INSERT INTO t1 SELECT ..." as doing row-by-row operations in PL/SQL will still be slower than SQL.

In either case, you can also use direct-path inserts by using INSERT /*+APPEND*/, which basically bypasses the DB cache and directly allocates and writes new blocks to data files. This can also reduce the amount of logging, depending on how you use it. This also has some implications, so please read the fine manual first.

Finally, if you are truncating and rebuilding the table it may be worthwhile to first drop (or mark unusable) and later rebuild indexes.

CaptainPicard
A: 

Hello,

Maybe one of your best option is to avoid Oracle as much as possible actually. I've been baffled by this myself, but very often a Java process can outperform many of the Oracle's utilities which either use OCI (read: SQL Plus) or will take up so much of your time to get right (read: SQL*Loader).

This doesn't prevent you to use specific hints either (like /APPEND/).

I've been pleasantly surprised each time I've turned to that kind of solution.

Cheers,

Rollo

Rollo Tomazzi