473,473 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

MERGE performance help DB2 UDB v8.1.9

We have a very poorly performing MERGE statement (an hour or more on
tables of ~10000 and ~100000). This may require building temporary
tables with appropriate indexes, but I thought I would ask your
collective opinion. Would building a comprehensive index on
nullid.angus_is improve this statement's performance?

merge into (select * from nullid.ANGUS_IN where bhid is null) t1
using (select ta.*, ts.regnum as sire_regnum, td.regnum as dam_regnum
from is3.animals ta
join is3.animals ts on ta.sire_bhid=ts.bhid
join is3.animals td on ta.dam_bhid=ts.bhid ) t2
on t1.tattoo=t2.tattoo
and t1.sex=t2.sex
and t1.birth_date=t2.birth_date
and t1.assoc=t2.assoc
and t1.sire_regnum=t2.sire_regnum
and t1.dam_regnum=t2.dam_regnum
when matched and t2.regnum is null then update
set t1.bhid = t2.bhid

The proposed index would be:

create index nullid.an_in_tsbd
on nullid.angus_in(tattoo, sex, birth_date,
assoc, sire_regnum, dam_regnum)
Jan 12 '06 #1
3 3506
Bob Stearns wrote:
We have a very poorly performing MERGE statement (an hour or more on
tables of ~10000 and ~100000). This may require building temporary
tables with appropriate indexes, but I thought I would ask your
collective opinion. Would building a comprehensive index on
nullid.angus_is improve this statement's performance?

merge into (select * from nullid.ANGUS_IN where bhid is null) t1
using (select ta.*, ts.regnum as sire_regnum, td.regnum as dam_regnum
from is3.animals ta
join is3.animals ts on ta.sire_bhid=ts.bhid
join is3.animals td on ta.dam_bhid=ts.bhid ) t2
on t1.tattoo=t2.tattoo
and t1.sex=t2.sex
and t1.birth_date=t2.birth_date
and t1.assoc=t2.assoc
and t1.sire_regnum=t2.sire_regnum
and t1.dam_regnum=t2.dam_regnum
when matched and t2.regnum is null then update
set t1.bhid = t2.bhid

The proposed index would be:

create index nullid.an_in_tsbd
on nullid.angus_in(tattoo, sex, birth_date,
assoc, sire_regnum, dam_regnum)

One of the most important criteria for MEREG to perform is that the
source produces provably (by DB2 that is) DISTINCT rows w.r.t. the ON
clause. If that is not the case MERGE requires that DB2 detects
duplicate updates and raises a runtime error. This is costly.
MERGE shines when the on clause is on a key.
In your case it's inetersting that you apply t2.regnum IS NULL in teh
MATCHED clause. Typically predicates there are used to distinguish
between UPDATE and DELETE branches.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
DB2 UDB for Linux, Unix, Windows
IBM Toronto Lab
Jan 12 '06 #2
Serge Rielau wrote:
Bob Stearns wrote:
We have a very poorly performing MERGE statement (an hour or more on
tables of ~10000 and ~100000). This may require building temporary
tables with appropriate indexes, but I thought I would ask your
collective opinion. Would building a comprehensive index on
nullid.angus_is improve this statement's performance?

merge into (select * from nullid.ANGUS_IN where bhid is null) t1
using (select ta.*, ts.regnum as sire_regnum, td.regnum as dam_regnum
from is3.animals ta
join is3.animals ts on ta.sire_bhid=ts.bhid
join is3.animals td on ta.dam_bhid=ts.bhid ) t2
on t1.tattoo=t2.tattoo
and t1.sex=t2.sex
and t1.birth_date=t2.birth_date
and t1.assoc=t2.assoc
and t1.sire_regnum=t2.sire_regnum
and t1.dam_regnum=t2.dam_regnum
when matched and t2.regnum is null then update
set t1.bhid = t2.bhid

The proposed index would be:

create index nullid.an_in_tsbd
on nullid.angus_in(tattoo, sex, birth_date,
assoc, sire_regnum, dam_regnum)


One of the most important criteria for MEREG to perform is that the
source produces provably (by DB2 that is) DISTINCT rows w.r.t. the ON
clause. If that is not the case MERGE requires that DB2 detects
duplicate updates and raises a runtime error. This is costly.
MERGE shines when the on clause is on a key.
In your case it's inetersting that you apply t2.regnum IS NULL in teh
MATCHED clause. Typically predicates there are used to distinguish
between UPDATE and DELETE branches.

Cheers
Serge

Thanks for the quick reply. You missed (or maybe thought I knew what was
doing:-) the not so obvious error in the last JOIN: ts.bhid should have
been td.bhid; the syntax scanner can not find logical errors. My only
excuse is that it was not written by me but a colleague.
Jan 12 '06 #3
Bob Stearns wrote:
Serge Rielau wrote:
Bob Stearns wrote:
We have a very poorly performing MERGE statement (an hour or more on
tables of ~10000 and ~100000). This may require building temporary
tables with appropriate indexes, but I thought I would ask your
collective opinion. Would building a comprehensive index on
nullid.angus_is improve this statement's performance?

merge into (select * from nullid.ANGUS_IN where bhid is null) t1
using (select ta.*, ts.regnum as sire_regnum, td.regnum as dam_regnum
from is3.animals ta
join is3.animals ts on ta.sire_bhid=ts.bhid
join is3.animals td on ta.dam_bhid=ts.bhid ) t2
on t1.tattoo=t2.tattoo
and t1.sex=t2.sex
and t1.birth_date=t2.birth_date
and t1.assoc=t2.assoc
and t1.sire_regnum=t2.sire_regnum
and t1.dam_regnum=t2.dam_regnum
when matched and t2.regnum is null then update
set t1.bhid = t2.bhid

The proposed index would be:

create index nullid.an_in_tsbd
on nullid.angus_in(tattoo, sex, birth_date,
assoc, sire_regnum, dam_regnum)

One of the most important criteria for MEREG to perform is that the
source produces provably (by DB2 that is) DISTINCT rows w.r.t. the ON
clause. If that is not the case MERGE requires that DB2 detects
duplicate updates and raises a runtime error. This is costly.
MERGE shines when the on clause is on a key.
In your case it's inetersting that you apply t2.regnum IS NULL in teh
MATCHED clause. Typically predicates there are used to distinguish
between UPDATE and DELETE branches.

Cheers
Serge

Thanks for the quick reply. You missed (or maybe thought I knew what was
doing:-) the not so obvious error in the last JOIN: ts.bhid should have
been td.bhid; the syntax scanner can not find logical errors. My only
excuse is that it was not written by me but a colleague.

Ah yes.. a bad on clause may do you in in no time but for long time

--
Serge Rielau
DB2 Solutions Development
DB2 UDB for Linux, Unix, Windows
IBM Toronto Lab
Jan 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kevin King | last post by:
I have a question about an assignment I have. I need to count the number of comparisons in my merge sort. I know that the function is roughly nlog(n), but I am definately coming up with too many...
2
by: Private Pyle | last post by:
AIX 5.1, DB2 8.1.3 64-bit ESE 5 partitions 1 catalog, 4 data. I have a situation where I have to update 269,000,000 rows in a table with the value in another table with just about the same number...
9
by: DraguVaso | last post by:
Hi, I have two DataTables (our DataViews or whatever that will suit the best for the solution). I want to merge these two DataTables the fastest as possible, but they have to be merged one table...
16
by: UDBDBA | last post by:
Hi All: I need some clarification on a MERGE statement. The database is on V8 FP12 (AIX) 64bit. The source table is tableA. The target is a View "FACT" with UNION ALL because of the 512 Gig...
0
by: sk.rasheedfarhan | last post by:
Hi all, I set the configuration for Merge replication for Subscription on one database and I have created the Merge replication for publication on another machine. And I updated columns of...
2
by: eavery | last post by:
Does anyone know of any documentation on the performance of partition merge/split? Does the merge or split of a partition cause any locking on the partitioned table? If you were merging or...
0
by: eavery | last post by:
Does anyone know of any documentation on the performance of partition merge/split? Does the merge or split of a partition cause any locking on the partitioned table? If you were merging or...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
24
by: Henry J. | last post by:
My app needs to insert thousand value rows into a mostly empty table (data are read from a file). I can either use inserts, or use merge. The advantage of using merge is that in the few cases...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.