Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > DB2

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 11:47 AM
Sam Durai
 
Posts: n/a
Default Merge Query Help

Hello, I need to merge a small table (of rows less than 100,sometimes
even 0 rows) to a big table (of rows around 4 billion). I used the PK
of the big table as merge key but merge does a table scan so it runs
for ever.

I checked the table and PK statistics of the big table and it looks
good. Please let me know if I need to check for something else.

Here are more details
Small table - Non Partitioned ( Node 0)
Big table - Partitioned across 7 logical nodes (Node 1 - 8)

Query:
MERGE INTO CARD.VIN_VEH_OPTNS AS A USING (
SELECT VEH_IDENT_NBR, OPTN_CD, ERR_FLAG
FROM ETL.STG_NEWS_VIN_VEH_OPTNS2
WHERE ERR_FLAG IN ('N', 'Y'))AS B ON (A.VEH_IDENT_NBR =
B.VEH_IDENT_NBR AND A.OPTN_CD =B.OPTN_CD AND
A.VEH_OPTN_CD_CSI =13)
WHEN NOT MATCHED
THEN
INSERT (VEH_IDENT_NBR, OPTN_CD, VEH_OPTN_CD_CSI, OPTN_INSTLT_TYP_CD,
PART_SERIAL_NBR, BROADCAST_CD, SOURCE_SYSTEM_CD, SOURCE_DT,
DWH_EFCTV_TIMSTM, DWH_UPD_TIMSTM)VALUES (B.VEH_IDENT_NBR,
B.OPTN_CD, 13, '', '', '', 34, Current Timestamp, '
2007-02-20 10:39:53', '2007-02-20 10:39:53')
ELSE IGNORE


Reorgchk stats of big table is as below
Table statistics:
SCHEMA NAME CARD OV NP FP ACTBLK
TSIZE F1 F2 F3 REORG
----------------------------------------------------------------------------------------
Table: CARD.VIN_VEH_OPTNS
CARD VIN_VEH_OPTNS 4.6e+09 0 3e+07 3e+07 - 4.96e
+11 0 97 97 ---
----------------------------------------------------------------------------------------

Index statistics:

SCHEMA NAME CARD LEAF ELEAF LVLS ISIZE NDEL
KEYS F4 F5 F6 F7 F8 REORG
-------------------------------------------------------------------------------------------------
Table: CARD.VIN_VEH_OPTNS
CARD VVO_IX1 5e+09 7e+06 6916 4 10 13755
1000 100 80 0 0 0 -----
CARD VVO_IX2 5e+09 7e+06 287 4 12 8e+05 1e
+07 100 78 0 0 0 -----
SYSIBM SQL061028160336900 5e+09 6e+07 0 5 27 84 5e
+09 98 68 1 0 0 -----
-------------------------------------------------------------------------------------------------

Indexes on Big table:
CARD VVO_IX1
D 1
+DWH_EFCTV_TIMSTM
CARD VVO_IX2
D 2 +DWH_UPD_TIMSTM
+VEH_OPTN_CD_CSI
SYSIBM SQL061028160336900
P 3 +VEH_IDENT_NBR+OPTN_CD
+VEH_OPTN_CD_CSI

Access Plan:
Optimizer Plan:

INSERT
( 2)
/ \
DTQ Table:
( 3) CARD
| VIN_VEH_OPTNS
TBSCAN
( 4)
|
TEMP
( 5)
|
FILTER
( 6)
|
FILTER
( 7)
|
TBSCAN
( 8)
|
SORT
( 9)
|
NLJOIN
( 10)
/ \
TBSCAN TBSCAN
( 11) ( 12)
| |
Table: TEMP
ETL ( 13)
STG_NEWS_VIN_VEH_OPTNS2 |
BTQ
( 14)
|
TBSCAN
( 15)
|
Table:
CARD
VIN_VEH_OPTNS


Please share your thoughts.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 11:47 AM
Serge Rielau
 
Posts: n/a
Default Re: Merge Query Help

Sam Durai wrote:
> Hello, I need to merge a small table (of rows less than 100,sometimes
> even 0 rows) to a big table (of rows around 4 billion). I used the PK
> of the big table as merge key but merge does a table scan so it runs
> for ever.
>
> I checked the table and PK statistics of the big table and it looks
> good. Please let me know if I need to check for something else.
>
> Here are more details
> Small table - Non Partitioned ( Node 0)
> Big table - Partitioned across 7 logical nodes (Node 1 - 8)
>
> Query:
> MERGE INTO CARD.VIN_VEH_OPTNS AS A USING (
> SELECT VEH_IDENT_NBR, OPTN_CD, ERR_FLAG
> FROM ETL.STG_NEWS_VIN_VEH_OPTNS2
> WHERE ERR_FLAG IN ('N', 'Y'))AS B ON (A.VEH_IDENT_NBR =
> B.VEH_IDENT_NBR AND A.OPTN_CD =B.OPTN_CD AND
> A.VEH_OPTN_CD_CSI =13)
> WHEN NOT MATCHED
> THEN
> INSERT (VEH_IDENT_NBR, OPTN_CD, VEH_OPTN_CD_CSI, OPTN_INSTLT_TYP_CD,
> PART_SERIAL_NBR, BROADCAST_CD, SOURCE_SYSTEM_CD, SOURCE_DT,
> DWH_EFCTV_TIMSTM, DWH_UPD_TIMSTM)VALUES (B.VEH_IDENT_NBR,
> B.OPTN_CD, 13, '', '', '', 34, Current Timestamp, '
> 2007-02-20 10:39:53', '2007-02-20 10:39:53')
> ELSE IGNORE
>
>
> Reorgchk stats of big table is as below
> Table statistics:
> SCHEMA NAME CARD OV NP FP ACTBLK
> TSIZE F1 F2 F3 REORG
> ----------------------------------------------------------------------------------------
> Table: CARD.VIN_VEH_OPTNS
> CARD VIN_VEH_OPTNS 4.6e+09 0 3e+07 3e+07 - 4.96e
> +11 0 97 97 ---
> ----------------------------------------------------------------------------------------
>
> Index statistics:
>
> SCHEMA NAME CARD LEAF ELEAF LVLS ISIZE NDEL
> KEYS F4 F5 F6 F7 F8 REORG
> -------------------------------------------------------------------------------------------------
> Table: CARD.VIN_VEH_OPTNS
> CARD VVO_IX1 5e+09 7e+06 6916 4 10 13755
> 1000 100 80 0 0 0 -----
> CARD VVO_IX2 5e+09 7e+06 287 4 12 8e+05 1e
> +07 100 78 0 0 0 -----
> SYSIBM SQL061028160336900 5e+09 6e+07 0 5 27 84 5e
> +09 98 68 1 0 0 -----
> -------------------------------------------------------------------------------------------------
>
> Indexes on Big table:
> CARD VVO_IX1
> D 1
> +DWH_EFCTV_TIMSTM
> CARD VVO_IX2
> D 2 +DWH_UPD_TIMSTM
> +VEH_OPTN_CD_CSI
> SYSIBM SQL061028160336900
> P 3 +VEH_IDENT_NBR+OPTN_CD
> +VEH_OPTN_CD_CSI
>
> Access Plan:
> Optimizer Plan:
>
> INSERT
> ( 2)
> / \
> DTQ Table:
> ( 3) CARD
> | VIN_VEH_OPTNS
> TBSCAN
> ( 4)
> |
> TEMP
> ( 5)
> |
> FILTER
> ( 6)
> |
> FILTER
> ( 7)
> |
> TBSCAN
> ( 8)
> |
> SORT
> ( 9)
> |
> NLJOIN
> ( 10)
> / \
> TBSCAN TBSCAN
> ( 11) ( 12)
> | |
> Table: TEMP
> ETL ( 13)
> STG_NEWS_VIN_VEH_OPTNS2 |
> BTQ
> ( 14)
> |
> TBSCAN
> ( 15)
> |
> Table:
> CARD
> VIN_VEH_OPTNS
>
>
> Please share your thoughts.
>

Do/Can you have dups in the source?
SELECT VEH_IDENT_NBR, OPTN_CD, ERR_FLAG
FROM ETL.STG_NEWS_VIN_VEH_OPTNS2
WHERE ERR_FLAG IN ('N', 'Y'))AS B

assuming you don't have a UNIQUE key on VEH_IDENT_NBR, OPTN_CD
I recommend SELECT VEH_IDENT_NBR, OPTN_CD, MAX(ERR_FLAG)
FROM ETL.STG_NEWS_VIN_VEH_OPTNS2
WHERE ERR_FLAG IN ('N', 'Y')
GROUP BY VEH_IDENT_NBR, OPTN_CD) AS B

Do you have statistics on the small table?

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 11:47 AM
Sam Durai
 
Posts: n/a
Default Re: Merge Query Help

On Feb 20, 12:44 pm, Serge Rielau <srie...@ca.ibm.com> wrote:
> Sam Durai wrote:
> > Hello, I need to merge a small table (of rows less than 100,sometimes
> > even 0 rows) to a big table (of rows around 4 billion). I used the PK
> > of the big table as merge key but merge does a table scan so it runs
> > for ever.

>
> > I checked the table and PK statistics of the big table and it looks
> > good. Please let me know if I need to check for something else.

>
> > Here are more details
> > Small table - Non Partitioned ( Node 0)
> > Big table - Partitioned across 7 logical nodes (Node 1 - 8)

>
> > Query:
> > MERGE INTO CARD.VIN_VEH_OPTNS AS A USING (
> > SELECT VEH_IDENT_NBR, OPTN_CD, ERR_FLAG
> > FROM ETL.STG_NEWS_VIN_VEH_OPTNS2
> > WHERE ERR_FLAG IN ('N', 'Y'))AS B ON (A.VEH_IDENT_NBR =
> > B.VEH_IDENT_NBR AND A.OPTN_CD =B.OPTN_CD AND
> > A.VEH_OPTN_CD_CSI =13)
> > WHEN NOT MATCHED
> > THEN
> > INSERT (VEH_IDENT_NBR, OPTN_CD, VEH_OPTN_CD_CSI, OPTN_INSTLT_TYP_CD,
> > PART_SERIAL_NBR, BROADCAST_CD, SOURCE_SYSTEM_CD, SOURCE_DT,
> > DWH_EFCTV_TIMSTM, DWH_UPD_TIMSTM)VALUES (B.VEH_IDENT_NBR,
> > B.OPTN_CD, 13, '', '', '', 34, Current Timestamp, '
> > 2007-02-20 10:39:53', '2007-02-20 10:39:53')
> > ELSE IGNORE

>
> > Reorgchk stats of big table is as below
> > Table statistics:
> > SCHEMA NAME CARD OV NP FP ACTBLK
> > TSIZE F1 F2 F3 REORG
> > ----------------------------------------------------------------------------------------
> > Table: CARD.VIN_VEH_OPTNS
> > CARD VIN_VEH_OPTNS 4.6e+09 0 3e+07 3e+07 - 4.96e
> > +11 0 97 97 ---
> > ----------------------------------------------------------------------------------------

>
> > Index statistics:

>
> > SCHEMA NAME CARD LEAF ELEAF LVLS ISIZE NDEL
> > KEYS F4 F5 F6 F7 F8 REORG
> > -------------------------------------------------------------------------------------------------
> > Table: CARD.VIN_VEH_OPTNS
> > CARD VVO_IX1 5e+09 7e+06 6916 4 10 13755
> > 1000 100 80 0 0 0 -----
> > CARD VVO_IX2 5e+09 7e+06 287 4 12 8e+05 1e
> > +07 100 78 0 0 0 -----
> > SYSIBM SQL061028160336900 5e+09 6e+07 0 5 27 84 5e
> > +09 98 68 1 0 0 -----
> > -------------------------------------------------------------------------------------------------

>
> > Indexes on Big table:
> > CARD VVO_IX1
> > D 1
> > +DWH_EFCTV_TIMSTM
> > CARD VVO_IX2
> > D 2 +DWH_UPD_TIMSTM
> > +VEH_OPTN_CD_CSI
> > SYSIBM SQL061028160336900
> > P 3 +VEH_IDENT_NBR+OPTN_CD
> > +VEH_OPTN_CD_CSI

>
> > Access Plan:
> > Optimizer Plan:

>
> > INSERT
> > ( 2)
> > / \
> > DTQ Table:
> > ( 3) CARD
> > | VIN_VEH_OPTNS
> > TBSCAN
> > ( 4)
> > |
> > TEMP
> > ( 5)
> > |
> > FILTER
> > ( 6)
> > |
> > FILTER
> > ( 7)
> > |
> > TBSCAN
> > ( 8)
> > |
> > SORT
> > ( 9)
> > |
> > NLJOIN
> > ( 10)
> > / \
> > TBSCAN TBSCAN
> > ( 11) ( 12)
> > | |
> > Table: TEMP
> > ETL ( 13)
> > STG_NEWS_VIN_VEH_OPTNS2 |
> > BTQ
> > ( 14)
> > |
> > TBSCAN
> > ( 15)
> > |
> > Table:
> > CARD
> > VIN_VEH_OPTNS

>
> > Please share your thoughts.

>
> Do/Can you have dups in the source?
> SELECT VEH_IDENT_NBR, OPTN_CD, ERR_FLAG
> FROM ETL.STG_NEWS_VIN_VEH_OPTNS2
> WHERE ERR_FLAG IN ('N', 'Y'))AS B
>
> assuming you don't have a UNIQUE key on VEH_IDENT_NBR, OPTN_CD
> I recommend SELECT VEH_IDENT_NBR, OPTN_CD, MAX(ERR_FLAG)
> FROM ETL.STG_NEWS_VIN_VEH_OPTNS2
> WHERE ERR_FLAG IN ('N', 'Y')
> GROUP BY VEH_IDENT_NBR, OPTN_CD) AS B
>
> Do you have statistics on the small table?
>
> Cheers
> Serge
> --
> Serge Rielau
> DB2 Solutions Development
> IBM Toronto Lab


Thanks for looking into the issue. We cannot have duplicates on
VEH_IDENT_NBR, OPTN_CD, ERR_FLAG. I do have updated stats on the small
table and most of the time this table would be empty so I'm not sure
whether Unique Index would be of help.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 11:47 AM
Serge Rielau
 
Posts: n/a
Default Re: Merge Query Help

Sam Durai wrote:
> Thanks for looking into the issue. We cannot have duplicates on
> VEH_IDENT_NBR, OPTN_CD, ERR_FLAG. I do have updated stats on the small
> table and most of the time this table would be empty so I'm not sure
> whether Unique Index would be of help.

Not on all three, but that doesn't help. Imporatnt is whether you could
have two (VEH_IDENT_NBR, OPTN_CD) with different ERR_FLAG.
because you join on (VEH_IDENT_NBR, OPTN_CD).
Anyway: try my rewrite and see what it does to the plan. It should
become much simpler. All the goo above the JOIN should go away (and
hopefully in the process remove the tablescan).


--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-27-2008, 11:47 AM
Sam Durai
 
Posts: n/a
Default Re: Merge Query Help

On Feb 20, 1:18 pm, Serge Rielau <srie...@ca.ibm.com> wrote:
> Sam Durai wrote:
> > Thanks for looking into the issue. We cannot have duplicates on
> > VEH_IDENT_NBR, OPTN_CD, ERR_FLAG. I do have updated stats on the small
> > table and most of the time this table would be empty so I'm not sure
> > whether Unique Index would be of help.

>
> Not on all three, but that doesn't help. Imporatnt is whether you could
> have two (VEH_IDENT_NBR, OPTN_CD) with different ERR_FLAG.
> because you join on (VEH_IDENT_NBR, OPTN_CD).
> Anyway: try my rewrite and see what it does to the plan. It should
> become much simpler. All the goo above the JOIN should go away (and
> hopefully in the process remove the tablescan).
>
> --
> Serge Rielau
> DB2 Solutions Development
> IBM Toronto Lab


Here is the latest plan as per modified query.


INSERT
( 2)
/ \
DTQ Table:
( 3) CARD
| VIN_VEH_OPTNS
TBSCAN
( 4)
|
TEMP
( 5)
|
FILTER
( 6)
|
NLJOIN
( 7)
/--/ \--\
GRPBY TBSCAN
( 8) ( 12)
| |
TBSCAN TEMP
( 9) ( 13)
| |
SORT BTQ
( 10) ( 14)
| |
TBSCAN TBSCAN
( 11) ( 15)
| |
Table: Table:
ETL CARD
STG_NEWS_VIN_VEH_OPTNS2 VIN_VEH_OPTNS


Query :
MERGE INTO CARD.VIN_VEH_OPTNS AS A USING (
SELECT VEH_IDENT_NBR, OPTN_CD, MAX(ERR_FLAG)
FROM ETL.STG_NEWS_VIN_VEH_OPTNS2
WHERE ERR_FLAG IN ('N', 'Y')
GROUP BY VEH_IDENT_NBR, OPTN_CD)AS B ON (A.VEH_IDENT_NBR =
B.VEH_IDENT_NBR AND A.OPTN_CD =B.OPTN_CD AND
A.VEH_OPTN_CD_CSI =13)
WHEN NOT MATCHED
THEN
INSERT (VEH_IDENT_NBR, OPTN_CD, VEH_OPTN_CD_CSI, OPTN_INSTLT_TYP_CD,
PART_SERIAL_NBR, BROADCAST_CD, SOURCE_SYSTEM_CD, SOURCE_DT,
DWH_EFCTV_TIMSTM, DWH_UPD_TIMSTM)VALUES (B.VEH_IDENT_NBR,
B.OPTN_CD, 13, '', '', '', 34, Current Timestamp, '
2007-02-20 10:39:53', '2007-02-20 10:39:53')
ELSE IGNORE

The initial query which I posted earlier uses the PK index on other
DPF enabled environment but not on this. Not sure what the reason
eventhough the stat looks good :-(

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-27-2008, 11:47 AM
mirof007
 
Posts: n/a
Default Re: Merge Query Help

Hi Sam, what version of DB2 are you using?

Miro

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-27-2008, 11:47 AM
Sam Durai
 
Posts: n/a
Default Re: Merge Query Help

On Feb 20, 8:01 pm, "mirof007" <mirof...@gmail.com> wrote:
> Hi Sam, what version of DB2 are you using?
>
> Miro


It is DB2 UDB V8.1 FP 10
DB21085I Instance "cardp1in" uses "64" bits and DB2 code release
"SQL08023"
with level identifier "03040106".
Informational tokens are "DB2 v8.1.1.96", "s050811", "U803920", and
FixPak
"10".
Product is installed at "/usr/opt/db2_08_01".

As I said it is a logically partitioned db on AIX 5.3 having 8 logical
nodes. The big table is split across 7 partitions while the other
small table is on partition 1.

Is there is something which I need to enable to make the optimizer use
the index.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-27-2008, 11:47 AM
Tonkuma
 
Posts: n/a
Default Re: Merge Query Help

On Feb 21, 2:07 am, "Sam Durai" <reachsamdu...@gmail.com> wrote:
> Hello, I need to merge a small table (of rows less than 100,sometimes
> even 0 rows) to a big table (of rows around 4 billion). I used the PK
> of the big table as merge key but merge does a table scan so it runs
> for ever.
>
> I checked the table and PK statistics of the big table and it looks
> good. Please let me know if I need to check for something else.
>
> Here are more details
> Small table - Non Partitioned ( Node 0)
> Big table - Partitioned across 7 logical nodes (Node 1 - 8)
>
> Query:
> MERGE INTO CARD.VIN_VEH_OPTNS AS A USING (
> SELECT VEH_IDENT_NBR, OPTN_CD, ERR_FLAG
> FROM ETL.STG_NEWS_VIN_VEH_OPTNS2
> WHERE ERR_FLAG IN ('N', 'Y'))AS B ON (A.VEH_IDENT_NBR =
> B.VEH_IDENT_NBR AND A.OPTN_CD =B.OPTN_CD AND
> A.VEH_OPTN_CD_CSI =13)
> WHEN NOT MATCHED
> THEN
> INSERT (VEH_IDENT_NBR, OPTN_CD, VEH_OPTN_CD_CSI, OPTN_INSTLT_TYP_CD,
> PART_SERIAL_NBR, BROADCAST_CD, SOURCE_SYSTEM_CD, SOURCE_DT,
> DWH_EFCTV_TIMSTM, DWH_UPD_TIMSTM)VALUES (B.VEH_IDENT_NBR,
> B.OPTN_CD, 13, '', '', '', 34, Current Timestamp, '
> 2007-02-20 10:39:53', '2007-02-20 10:39:53')
> ELSE IGNORE
>


I thought that it is worth to try following index.
Because, to check MATCHED or NOT, data of columns A.VEH_IDENT_NBR,
A.OPTN_CD, A.VEH_OPTN_CD_CSI from Table "CARD.VIN_VEH_OPTNS AS A" are
necessary. If there is no appropriate index, DB2 need to see table
itself to acquire these values. Consequentry, tablespace scan may be
inevitable.
CREATE INDEX CARD_IDNBR_CD_CSI ON CARD.VIN_VEH_OPTNS
(VEH_IDENT_NBR, OPTN_CD, VEH_OPTN_CD_CSI)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-27-2008, 11:47 AM
Sam Durai
 
Posts: n/a
Default Re: Merge Query Help

On Feb 20, 9:32 pm, "Tonkuma" <tonk...@jp.ibm.com> wrote:
> On Feb 21, 2:07 am, "Sam Durai" <reachsamdu...@gmail.com> wrote:
>
>
>
> > Hello, I need to merge a small table (of rows less than 100,sometimes
> > even 0 rows) to a big table (of rows around 4 billion). I used the PK
> > of the big table as merge key but merge does a table scan so it runs
> > for ever.

>
> > I checked the table and PK statistics of the big table and it looks
> > good. Please let me know if I need to check for something else.

>
> > Here are more details
> > Small table - Non Partitioned ( Node 0)
> > Big table - Partitioned across 7 logical nodes (Node 1 - 8)

>
> > Query:
> > MERGE INTO CARD.VIN_VEH_OPTNS AS A USING (
> > SELECT VEH_IDENT_NBR, OPTN_CD, ERR_FLAG
> > FROM ETL.STG_NEWS_VIN_VEH_OPTNS2
> > WHERE ERR_FLAG IN ('N', 'Y'))AS B ON (A.VEH_IDENT_NBR =
> > B.VEH_IDENT_NBR AND A.OPTN_CD =B.OPTN_CD AND
> > A.VEH_OPTN_CD_CSI =13)
> > WHEN NOT MATCHED
> > THEN
> > INSERT (VEH_IDENT_NBR, OPTN_CD, VEH_OPTN_CD_CSI, OPTN_INSTLT_TYP_CD,
> > PART_SERIAL_NBR, BROADCAST_CD, SOURCE_SYSTEM_CD, SOURCE_DT,
> > DWH_EFCTV_TIMSTM, DWH_UPD_TIMSTM)VALUES (B.VEH_IDENT_NBR,
> > B.OPTN_CD, 13, '', '', '', 34, Current Timestamp, '
> > 2007-02-20 10:39:53', '2007-02-20 10:39:53')
> > ELSE IGNORE

>
> I thought that it is worth to try following index.
> Because, to check MATCHED or NOT, data of columns A.VEH_IDENT_NBR,
> A.OPTN_CD, A.VEH_OPTN_CD_CSI from Table "CARD.VIN_VEH_OPTNS AS A" are
> necessary. If there is no appropriate index, DB2 need to see table
> itself to acquire these values. Consequentry, tablespace scan may be
> inevitable.
> CREATE INDEX CARD_IDNBR_CD_CSI ON CARD.VIN_VEH_OPTNS
> (VEH_IDENT_NBR, OPTN_CD, VEH_OPTN_CD_CSI)


Thats the PK in big table.
SYSIBM SQL061028160336900
P 3 +VEH_IDENT_NBR+OPTN_CD
+VEH_OPTN_CD_CSI

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-27-2008, 11:47 AM
Serge Rielau
 
Posts: n/a
Default Re: Merge Query Help

Sam Durai wrote:
> On Feb 20, 9:32 pm, "Tonkuma" <tonk...@jp.ibm.com> wrote:
>> On Feb 21, 2:07 am, "Sam Durai" <reachsamdu...@gmail.com> wrote:
>>
>>
>>
>>> Hello, I need to merge a small table (of rows less than 100,sometimes
>>> even 0 rows) to a big table (of rows around 4 billion). I used the PK
>>> of the big table as merge key but merge does a table scan so it runs
>>> for ever.
>>> I checked the table and PK statistics of the big table and it looks
>>> good. Please let me know if I need to check for something else.
>>> Here are more details
>>> Small table - Non Partitioned ( Node 0)
>>> Big table - Partitioned across 7 logical nodes (Node 1 - 8)
>>> Query:
>>> MERGE INTO CARD.VIN_VEH_OPTNS AS A USING (
>>> SELECT VEH_IDENT_NBR, OPTN_CD, ERR_FLAG
>>> FROM ETL.STG_NEWS_VIN_VEH_OPTNS2
>>> WHERE ERR_FLAG IN ('N', 'Y'))AS B ON (A.VEH_IDENT_NBR =
>>> B.VEH_IDENT_NBR AND A.OPTN_CD =B.OPTN_CD AND
>>> A.VEH_OPTN_CD_CSI =13)
>>> WHEN NOT MATCHED
>>> THEN
>>> INSERT (VEH_IDENT_NBR, OPTN_CD, VEH_OPTN_CD_CSI, OPTN_INSTLT_TYP_CD,
>>> PART_SERIAL_NBR, BROADCAST_CD, SOURCE_SYSTEM_CD, SOURCE_DT,
>>> DWH_EFCTV_TIMSTM, DWH_UPD_TIMSTM)VALUES (B.VEH_IDENT_NBR,
>>> B.OPTN_CD, 13, '', '', '', 34, Current Timestamp, '
>>> 2007-02-20 10:39:53', '2007-02-20 10:39:53')
>>> ELSE IGNORE

>> I thought that it is worth to try following index.
>> Because, to check MATCHED or NOT, data of columns A.VEH_IDENT_NBR,
>> A.OPTN_CD, A.VEH_OPTN_CD_CSI from Table "CARD.VIN_VEH_OPTNS AS A" are
>> necessary. If there is no appropriate index, DB2 need to see table
>> itself to acquire these values. Consequentry, tablespace scan may be
>> inevitable.
>> CREATE INDEX CARD_IDNBR_CD_CSI ON CARD.VIN_VEH_OPTNS
>> (VEH_IDENT_NBR, OPTN_CD, VEH_OPTN_CD_CSI)

>
> Thats the PK in big table.
> SYSIBM SQL061028160336900
> P 3 +VEH_IDENT_NBR+OPTN_CD
> +VEH_OPTN_CD_CSI
>

Sam woudl you mind doing an EXPLAIN PLAN followed by db2exfmt rather
than db2expl.
db2exfmt produces has a lot more information. db2expln merely
disassembles the runtime into a plan.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:03 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 4