dbTalk Databases Forums  

DB2 MERGE STATEMENT ARE using table scan

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss DB2 MERGE STATEMENT ARE using table scan in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Anwei Shen
 
Posts: n/a

Default DB2 MERGE STATEMENT ARE using table scan - 03-06-2011 , 10:44 PM






I have a merge statement run pretty slow, when checking explain. It
simply scan both tables.
Source table and Target table are partitioned by different columns,
both indexed.
This is on db2 v9.1
merge tgt
using src
on tgt.primarykey = src.key
when matched
when not matched.

I am expecting it scan only the src table.
Any idea?

Reply With Quote
  #2  
Old   
Anwei Shen
 
Posts: n/a

Default Re: DB2 MERGE STATEMENT ARE using table scan - 03-07-2011 , 10:26 PM






On Mar 6, 11:44*pm, Anwei Shen <shenan... (AT) gmail (DOT) com> wrote:
Quote:
I have a merge statement run pretty slow, when checking explain. It
simply scan both tables.
Source table and Target table are partitioned by different columns,
both indexed.
This is on db2 v9.1
merge tgt
using src
on tgt.primarykey = src.key
when matched
when not matched.

I am expecting it scan only the src table.
Any idea?
Even I create another table like Target table using the same partition
key, merge will do 2 table scan.

Reply With Quote
  #3  
Old   
Frederik Engelen
 
Posts: n/a

Default Re: DB2 MERGE STATEMENT ARE using table scan - 03-08-2011 , 10:06 AM



On Mar 8, 5:26*am, Anwei Shen <shenan... (AT) gmail (DOT) com> wrote:
Quote:
On Mar 6, 11:44*pm, Anwei Shen <shenan... (AT) gmail (DOT) com> wrote:

I have a merge statement run pretty slow, when checking explain. It
simply scan both tables.
Source table and Target table are partitioned by different columns,
both indexed.
This is on db2 v9.1
merge tgt
using src
on tgt.primarykey = src.key
when matched
when not matched.

I am expecting it scan only the src table.
Any idea?

Even I create another table like Target table using the same partition
key, merge will do 2 table scan.
Hello Anwei,

Could you provide some DDL that would allow us to recreate your
situation? There are many factors involved in the optimizer's decision
to use a table scan. The information you're giving is too vague to
comment on.

--
Frederik Engelen

Reply With Quote
  #4  
Old   
Serge Rielau
 
Posts: n/a

Default Re: DB2 MERGE STATEMENT ARE using table scan - 03-08-2011 , 10:06 AM



On 3/7/2011 8:26 PM, Anwei Shen wrote:
Quote:
On Mar 6, 11:44 pm, Anwei Shen<shenan... (AT) gmail (DOT) com> wrote:
I have a merge statement run pretty slow, when checking explain. It
simply scan both tables.
Source table and Target table are partitioned by different columns,
both indexed.
This is on db2 v9.1
merge tgt
using src
on tgt.primarykey = src.key
when matched
when not matched.

I am expecting it scan only the src table.
Any idea?

Even I create another table like Target table using the same partition
key, merge will do 2 table scan.
Drop the optimization level to 3. That disables hashjoin.
Do you have stats on the source table? How big is the source table
compared to the target table?


--
Serge Rielau
SQL Architect DB2 for LUW, IBM Toronto Lab
Blog: tinyurl.com/SQLTips4DB2
Wiki: tinyurl.com/Oracle2DB2Wiki
Twitter: srielau

Reply With Quote
  #5  
Old   
Frederik Engelen
 
Posts: n/a

Default Re: DB2 MERGE STATEMENT ARE using table scan - 03-08-2011 , 10:24 AM



On Mar 8, 5:06*pm, Serge Rielau <srie... (AT) ca (DOT) ibm.com> wrote:
Quote:
On 3/7/2011 8:26 PM, Anwei Shen wrote:



On Mar 6, 11:44 pm, Anwei Shen<shenan... (AT) gmail (DOT) com> *wrote:
I have a merge statement run pretty slow, when checking explain. It
simply scan both tables.
Source table and Target table are partitioned by different columns,
both indexed.
This is on db2 v9.1
merge tgt
using src
on tgt.primarykey = src.key
when matched
when not matched.

I am expecting it scan only the src table.
Any idea?

Even I create another table like Target table using the same partition
key, merge will do 2 table scan.

Drop the optimization level to 3. That disables hashjoin.
Do you have stats on the source table? How big is the source table
compared to the target table?

--
Serge Rielau
SQL Architect DB2 for LUW, IBM Toronto Lab
Blog: * *tinyurl.com/SQLTips4DB2
Wiki: * *tinyurl.com/Oracle2DB2Wiki
Twitter: srielau- Hide quoted text -

- Show quoted text -
"The information you're giving is too vague to comment on."

Ok, yes, well, euhm, Serge can, of course...

--
Frederik

Reply With Quote
  #6  
Old   
Mark A
 
Posts: n/a

Default Re: DB2 MERGE STATEMENT ARE using table scan - 03-08-2011 , 04:45 PM



"Serge Rielau" <srielau (AT) ca (DOT) ibm.com> wrote

Quote:
Drop the optimization level to 3. That disables hashjoin.
Do you have stats on the source table? How big is the source table
compared to the target table?
--
Serge Rielau
SQL Architect DB2 for LUW, IBM Toronto Lab
Blog: tinyurl.com/SQLTips4DB2
Wiki: tinyurl.com/Oracle2DB2Wiki
Twitter: srielau
Any chance of setting optimization level at the statement level (sort of
like can be done with isolation level)?

Reply With Quote
  #7  
Old   
Helmut Tessarek
 
Posts: n/a

Default Re: DB2 MERGE STATEMENT ARE using table scan - 03-08-2011 , 05:23 PM



Quote:
Any chance of setting optimization level at the statement level (sort of
like can be done with isolation level)?
db2 set current query optimization 3
<run your statement here>
db2 set current query optimization <old value>

--
Helmut K. C. Tessarek
DB2 Performance and Development
IBM Toronto Lab

Reply With Quote
  #8  
Old   
Helmut Tessarek
 
Posts: n/a

Default Re: DB2 MERGE STATEMENT ARE using table scan - 03-08-2011 , 05:36 PM



Quote:
Any chance of setting optimization level at the statement level (sort of
like can be done with isolation level)?
You can't set the optimization level at statement level (within the SQL
statement), but you can use the following special register:

set current query optimization = 3
<run your statement here>
set current query optimization = <old value>

--
Helmut K. C. Tessarek
DB2 Performance and Development
IBM Toronto Lab

Reply With Quote
  #9  
Old   
Mark A
 
Posts: n/a

Default Re: DB2 MERGE STATEMENT ARE using table scan - 03-08-2011 , 11:40 PM



"Helmut Tessarek" <tessarek (AT) evermeet (DOT) cx> wrote

Quote:
Any chance of setting optimization level at the statement level (sort of
like can be done with isolation level)?

You can't set the optimization level at statement level (within the SQL
statement), but you can use the following special register:

set current query optimization = 3
run your statement here
set current query optimization = <old value

--
Helmut K. C. Tessarek
DB2 Performance and Development
IBM Toronto Lab
Yes, I already know that. My question is whether there is any chance of IBM
making an enhancement to DB2 to have it set at the statement level.

Changing the current optimization is unacceptable in most cases.

Reply With Quote
  #10  
Old   
Serge Rielau
 
Posts: n/a

Default Re: DB2 MERGE STATEMENT ARE using table scan - 03-09-2011 , 04:10 AM



Mark,

http://publib.boulder.ibm.com/infoce...c/c0024649.htm

Cheers
Serge

PS: No this is not the complete answer, but knowing you you should be
able to connect the dots...

--
Serge Rielau
SQL Architect DB2 for LUW, IBM Toronto Lab
Blog: tinyurl.com/SQLTips4DB2
Wiki: tinyurl.com/Oracle2DB2Wiki
Twitter: srielau

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.