Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why INSERT /*+APPEND*/ is used?

Tags:

insert

oracle

A java program is doing bulk insertion into the Oracle table. It works fine for 100-200 records but its hanging for more than 4000 records.

When I checked the query, its having INSERT /*+APPEND*/ in it.

What is INSERT /*+APPEND*/ and why is it used in INSERT queries? Is the program hanging because of this thing?

like image 904
Mithun Khatri Avatar asked May 23 '14 07:05

Mithun Khatri


People also ask

What is the use of append hint?

The APPEND hint tells the database to find the last block into which the table's data has ever been inserted. The new records are then inserted starting in the first block of the new extent allocated above the table's high watermark (HWM), which will be explained shortly.

Does insert into append?

You can also use INSERT INTO to append a set of records from another table or query by using the SELECT … FROM clause as shown above in the multiple-record append query syntax. In this case, the SELECT clause specifies the fields to append to the specified target table.

Does append hint lock table?

Oracle documentation indicates that the APPEND hint does a direct-path load and hence the table becomes unaccessible for DMLs from other sessions till the direct-path load is complete.

What are hints in Oracle?

Hints provide a mechanism to instruct the optimizer to choose a certain query execution plan based on the specific criteria. For example, you might know that a certain index is more selective for certain queries. Based on this information, you might be able to choose a more efficient execution plan than the optimizer.


1 Answers

It's a SQL optimizer hint. In your case most likely it has NO impact. Maybe it's a premature optimization.

This hint should enforce so called direct path insert, which bypasses Oracle's buffer cache and writes data directly into data-files. Data are appended beyond high water mark(HWM) - ignoring table's free space map, no triggers are fired and no constraints are checked. On the other hand this type of insert is blocking. Only one session can use it on particular table at the same time.

An excerpt from docs:

"The APPEND hint is only supported with the subquery syntax of the INSERT statement, not the VALUES clause. If you specify the APPEND hint with the VALUES clause, it is ignored and conventional insert will be used. To use direct-path INSERT with the VALUES clause, refer to "APPEND_VALUES Hint" This hint only works when you use INSERT as SELECT statement

 insert into <table> SELECT * FROM ....

When you insert values Oracle silently ignores it. Newer Oracle versions also support APPEND_VALUES hint.

If you want to validate the hint being used open Toad or SQL Developer, select session browser, find that particular session and it's current SQL and exec plan. When you see in the exec plan something like "INSERT into TABLE CONVENTIONAL" then the hint is ignored. If you see "INSERT as SELECT" then you are using direct path load.

like image 126
ibre5041 Avatar answered Sep 18 '22 08:09

ibre5041