Skip to Main Content
  • Questions
  • APPEND hint in MERGE without INSERT clause

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Zdenek.

Asked: December 12, 2016 - 2:08 pm UTC

Last updated: March 16, 2018 - 3:59 am UTC

Version: 11g

Viewed 10K+ times! This question is

You Asked

Hello,
from the performance point of view: does it make sense to add the APPEND hint into the MERGE statement in that case there is only an UPDATE clause? If yes, what is the benefit?

Thank you,
Zdenek

and Connor said...

See

https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:6135888056554

for a demo.

APPEND will assist the insert portion of a merge, but not the update.


Rating

  (2 ratings)

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

Comments

Zdenek Zavadil, December 13, 2016 - 7:59 am UTC

Thank you for the answer. I was told that the APPEND hint has the effect on updating the indexes even in case that only UPDATE clause is present. They are supposedly updated not during but after the MERGE.
Can you please comment on this?
Connor McDonald
December 15, 2016 - 1:56 am UTC

I dont think that will be the case. If APPEND was 'active' then the table would be locked, and would not be available for query even in the current session until a commit was issued. But I dont see that:

SQL> create table t1
  2      as
  3      select object_id, owner, rpad('*',80,'*') data
  4        from all_objects;

Table created.

SQL>
SQL> create table t2
  2      as
  3      select * from t1;

Table created.

SQL>
SQL> create index t2ix on t2 ( owner );

Index created.

SQL>
SQL> merge /*+ append */ into t2
  2      using ( select * from t1 where object_id <= 20000 ) t1
  3      on ( t1.object_id = t2.object_id )
  4      when matched then update set data = substr(t1.data,1,79), owner = lower(t1.owner);

18447 rows merged.

--
-- a query from the same session still works
--
SQL>
SQL>
SQL> select count(*) from t2;

  COUNT(*)
----------
     97859

--
-- and from a *different* session, I can still do DML on t2
--
SQL> delete from t2 where object_id > 80000;

19493 rows deleted.



So I'm pretty sure its just a regular update.

merge append with HCC?

Aps, March 15, 2018 - 2:04 pm UTC

Hi guys,

Would it make sense to use merge /*+ append */ into ... on a table with COMPRESS (exadata option)?

SQL> create table t1
2 as
3 select object_id, owner, rpad('*',80,'*') data
4 from all_objects;

Table created.

SQL>
SQL> create table t2
2 as
3 select * from t1;

Table created.

SQL> alter table t2 compress for query high;

SQL> merge /*+ append */ into t2
2 using ( select * from t1 where object_id <= 20000 ) t1
3 on ( t1.object_id = t2.object_id )
4 when matched then update set data = substr(t1.data,1,79), owner = lower(t1.owner);

OR is there a better way to compress the data after a MERGE such as ALTER TABLE ... MOVE ...;


Connor McDonald
March 16, 2018 - 3:59 am UTC

The APPEND hint in a merge only applies to the insert portion, so no benefit for an update whether you are HCC or not.

In general, if you are updating a large amount of data on HCC, you will be better off potentially truncate/reload or similar option. Decompressing data is very expensive, and as you've surmised, typically requires another operation afterwards to get the compression re-applied.