> /---+---\
> 98031.8 5.03874e+07
[quoted text clipped - 20 lines]
> 269658
> 143952
This stack does the accounting to assure that each row in the target is
matched by at most one row in the source.
It gets added when Db2 fails to prove that the ON clause identifies
unique rows.
Now, semantically I don't see why it should care if a a single source
matches multiple targets.
>on B.col1 = A.col1
> and B.col2 = A.col2
Is tableA(col1, col2) a unique key?
Cheers
Serge
PS; I hate hashjoins with MERGE. Drop the optimization level to 3
(disable hashjoin) and see what happens.

Signature
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
UDBDBA - 07 Apr 2006 01:57 GMT
Yes. FOr the source tableA(col1,col2) is unique (infact col1 is unique
on tableA). But the same col1 on target tableB is not unique.
Counts for tableA: Source table
=========================
count(distinct col1) = 2450795
count(distinct col2) = 1
count(col1) = 2450795
count(col2) = 2450795
Counts for tableB: Target table
=========================
count(distinct col1) = 15197539
count(distinct col2) = 1
count(col1) = 50387384
count(col2) = 7950845
Thanks for your time & appreciate all the help.
Vijay
UDBDBA - 07 Apr 2006 02:01 GMT
Correction on the counts:
For counts on tableB: Target table
===========================
count(distinct col1) = 2450795
count(distinct col2) = 1
count(col1) = 50387384
count(col2) = 2450795
Thanks.
Vijay
UDBDBA - 07 Apr 2006 02:27 GMT
Hi Serge:
I turned volatile ON and gave selectivity of 0.00001 for col2, col3 and
col4 (on all = predicates). This time the merge finished in 84 minutes
at optimizer level 5. That's a major improvement compared to running
forever. And you were right about HSJOIN, The new plan has NLJOIN and
does improve merge performance.
By using selectivity, did i just get lucky?
Here is the new access plan:
Access Plan:
-----------
Total Cost: 48.673
Query Degree: 0
Rows
RETURN
( 1)
Cost
I/O
|
9.80318e-06
UPDATE
( 2)
48.673
4.3619
/----+----\
9.80318e-06 5.03874e+07
FILTER TABLE: STELLA
( 3) TARGET_TABLE
48.6726
4.36189
|
0.000245079
NLJOIN
( 4)
48.6726
4.36189
/-----------+-----------\
0.000245079 5.23167e-11
FETCH FETCH
( 5) ( 7)
35.8071 25.7169
3.36186 2.00003
/---+---\ /----+---\
24.5079 2.4508e+06 3.3155e-05 5.03874e+07
IXSCAN TABLE: STAGE IXSCAN TABLE: STELLA
( 6) SOURCE_TABLE ( 8) TARGET_TABLE
21.2964 25.7164
2 2
| |
2.4508e+06 5.03874e+07
INDEX: DB2DW1 INDEX: DB2DW1
IDX6040122122900 IDX6040122141000
thanks!
Vijay
Serge Rielau - 07 Apr 2006 23:28 GMT
> Hi Serge:
> I turned volatile ON and gave selectivity of 0.00001 for col2, col3 and
[quoted text clipped - 51 lines]
> INDEX: DB2DW1 INDEX: DB2DW1
> IDX6040122122900 IDX6040122141000
Perfect plan!
I'm a bit confused because the mess above the join also went away, but I
take it. I imagine that the SELECTIVITY helped to change to NLJOIN.
This is how a well behaved MERGE should look like!
Now you can add your INSERT back it AFTER the UPDATE branch.
This should add a above TEMP (can't be helped) and the INSERT on top of
that.
Cheers
Serge

Signature
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
UDBDBA - 07 Apr 2006 23:43 GMT
Thanks Serge and others for the inputs
Vijay
Gregor Kovač - 10 Apr 2006 09:42 GMT
> Thanks Serge and others for the inputs
>
> Vijay
Hi!
Can you please post the latest statement so I can compare it to the original
and see what exactly did you do?
Best regards,
Kovi

Signature
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
| Gregor Kovac | Gregor.Kovac@mikropis.si |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~