Skip to Main Content
  • Questions
  • direct path insert vs bulk insert in oracle

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Bimal.

Asked: April 19, 2007 - 5:52 am UTC

Last updated: June 19, 2013 - 8:14 pm UTC

Version: 10g

Viewed 10K+ times! This question is

You Asked

Hi Tom,

First, I would like to thank you for helping out so many people in the world.

Question:
In oracle 10g it is said that bulk insert will give a better performance. Can you please suggest which option should be used in a batch requirement when lot of records (100-150k )needs to be inserted. Direct path insert (with APPEND hints) or bulk insert in oracle using FORALL after bulk collecting the data in a colection.

Limitations of each of the above option will also help.

Regards
Bimal

and Tom said...

In Oracle it is said that operations performed in BULK will generally outperform slow by slow processing - 10g, 9i, 7.x, whatever version.

In fact, if you can get it into a SINGLE SQL STATEMENT, the biggest bulk process of them all, you are in general best off...


150,000 is a very small number of records.


My choice would be - just a normal insert. There would typically be no need for a direct path operation on such a tiny set of data. The normal conventional path insert would be free to use existing free space (whereas a direct path insert will not, it will always allocate new space above the high water mark).


So, if this is data to be loaded from a file, I would use:

insert into table select * from external_table;

that is, the file would be mapped as an external table (so you can query the file as if it were a table) and just inserted.


I would not write any code for this at all - if some of the data might "fail", I would use the new DML error logging feature of 10g
http://asktom.oracle.com/Misc/how-cool-is-this.html

but NO CODE, just an insert.

If you needed to load over a network (eg: the file is on your pc, the server is over "there" somewhere), then I would use sqlldr - but again NO CODE.


Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

GSR, November 06, 2008 - 5:05 pm UTC

Hi Tom,

Currently I am working on the same scenario,But I need to insert 350 million records using insert/*+append*/(Direct path insertion).DML error logging feature of 10g have some limitations like it will not raise this clause in case of unique constrian voilation.In this scenario How do I log the errors??
Tom Kyte
November 11, 2008 - 2:36 pm UTC

you have two choices

a) disable constraint, insert append, enable constraint with "exceptions into" afterwards

b) do not use direct path.


well, ok, three

c) use direct path, leave constraint on, but have the statement fail upon duplicates.

Performnace in multi user environment while doing a bulk insert

Pradeep, June 19, 2013 - 10:15 am UTC

Hi Tom,

We have a scenario where in a multiuser OLTP system bulk insertions are happening (millions of rows ).....at the same time many users are accessing data and facing performance issues. How we can improve the performance...

What would you suggest to handle these bulk inserts and mulch user access.... Since tables are getting stale very frequently due to heavy inserts.

Tom Kyte
June 19, 2013 - 8:14 pm UTC

what does it mean "tables are getting stale"?

I'd need more information - this sounds like something partitioning was built for - have the load processes load into their own tables using direct path and after they've loaded and indexed the data - exchange those partitions into the larger table. In that fashion, the loaders do not contend with each other nor do the impose any extra work on the readers and they can all use direct path.