Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question.

Asked: February 15, 2013 - 12:49 pm UTC

Last updated: February 19, 2013 - 9:21 am UTC

Version: 11.2g

Viewed 10K+ times! This question is

You Asked

Hi Tom,

We upgraded an application from Oracle 9i that used Append hint while inserting data into table for Direct-Path Inserts.

While going through Oracle 11g documentation I came to know that Append will not work if Valus clause is used and Append_Values should be used instead. Is that the behaviour is changed in Oracle 11g where as in Oracle 9i it used to work with Values clause.

I used this http://docs.oracle.com/cd/E11882_01/server.112/e25494.pdf as reference

and Tom said...

APPEND never worked (except for a short time in 11.1 - but that was a bug and fixed in a patch set) with the VALUES clause.


It never worked as a direct path in 9i, never, not any release

and *thank goodness* it never did, think about the horrible consequences if it did!!!

insert /*+ APPEND */ into t values ( 1, 2, 3 );

that would place one row per block - since direct path only writes above the high water mark and never reuses existing space!!!


the append_values is only useful if you are bulk loading (array inserting using OCI for forall processing in plsql for example) 1000's of rows at a time.


do not ever stick the append_values on a single row insert!!! not unless you want one row per block and a table that only grows over time, never reuses any space.

Rating

  (3 ratings)

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

Comments

APPEND_VALUES

A reader, February 16, 2013 - 11:47 pm UTC

Thank you Tom.

So, "it never worked with any release of Oracle" you mean Optimizer never used Append hint?
Tom Kyte
February 19, 2013 - 9:21 am UTC

it isn't an optimizer hint really truy - it doesn't change the plan.


/*+ APPEND */ only works if

a) there are no triggers
b) there is no RI regarding this table in effect
c) you used "as select", not values

otherwise it was silently ignored.

ops$tkyte%ORA11GR2> create table p ( x int primary key );
Table created.

ops$tkyte%ORA11GR2> create table c ( x references p );
Table created.

ops$tkyte%ORA11GR2> insert into p values ( 1 );
1 row created.

ops$tkyte%ORA11GR2> select * from p;

         X
----------
         1

ops$tkyte%ORA11GR2> commit;
Commit complete.


ops$tkyte%ORA11GR2> insert /*+ APPEND */ into p values ( 2 );
1 row created.

ops$tkyte%ORA11GR2> select * from p;

         X
----------
         1
         2

ops$tkyte%ORA11GR2> commit;
Commit complete.

<b>in a conventional path insert, you can select from the table right 
after modifying it.  Not so with direct path:</b>

ops$tkyte%ORA11GR2> insert /*+ APPEND */ into p select 3 from dual;
1 row created.

ops$tkyte%ORA11GR2> select * from p;
select * from p
*
ERROR at line 1:
ORA-12838: cannot read/modify an object after modifying it in parallel

<b>so, if we direct path for real - we cannot from it select until we commit...</b>

ops$tkyte%ORA11GR2> commit;
Commit complete.

ops$tkyte%ORA11GR2> create or replace trigger p
  2  before insert on p for each row
  3  begin
  4          dbms_output.put_line( 'hello world' );
  5  end;
  6  /
Trigger created.

ops$tkyte%ORA11GR2> insert /*+ APPEND */ into p select 4 from dual;
hello world

1 row created.

<b>that shows trigger prevents direct path</b>

ops$tkyte%ORA11GR2> select * from p;

         X
----------
         1
         2
         3
         4

ops$tkyte%ORA11GR2> commit;

Commit complete.

ops$tkyte%ORA11GR2> 
ops$tkyte%ORA11GR2> insert into c select 1 from dual;

1 row created.

ops$tkyte%ORA11GR2> select * from c;

         X
----------
         1

ops$tkyte%ORA11GR2> commit;

Commit complete.

<b>and that shows if you have RI, you cannot direct path with insert append</b>

Oleksandr Alesinskyy, February 19, 2013 - 6:37 am UTC

Hints do not cause errors even if used inappropriately - they are just silently ignored. So you used an APPEND hint in Oracle 9i to no avail - it has not affected anything.

A, February 20, 2013 - 4:05 am UTC

Thanks for the example. Was not aware of this.

More to Explore

Hints

Need more information on hints? Check out the complete hint descriptions