If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Why show table scan

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-31-11, 08:25
automona automona is offline
Registered User
 
Join Date: Dec 2011
Posts: 10
Why show table scan

Hi All,

I'm tuning query but this query not use index

ex.

Code:
SELECT CONSULTING.CONSULTING_ID
, CUSTOMER.TSIUSERID
FROM L_CONSULTING CONSULTING 
LEFT OUTER JOIN L_CUSTOMER CUSTOMER 
ON CONSULTING.CCCUSTID = CUSTOMER.CCCUSTID

Index
Code:
CREATE INDEX IDX_L_CONSULTING_CCCUSTID
ON L_CONSULTING(CCCUSTID);

ALTER TABLE L_CUSTOMER
    ADD CONSTRAINT L_CUSTOMER_PK
	PRIMARY KEY (CCCUSTID);
I also attached explain plan.
Attached Thumbnails
Why show table scan-explain.png  
Reply With Quote
  #2 (permalink)  
Old 01-01-12, 11:42
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
as there is no where clause - it has to open a table and this with a complete scan and use index for join
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #3 (permalink)  
Old 01-04-12, 00:19
fengsun2 fengsun2 is offline
Registered User
 
Join Date: Nov 2011
Posts: 124
The join method db2 chose is hsjoin ,which can not use indexes at all.
Reply With Quote
  #4 (permalink)  
Old 01-05-12, 00:04
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
Can you explain why hash join cannot use indexes?
Reply With Quote
  #5 (permalink)  
Old 01-05-12, 02:52
lelle12 lelle12 is offline
Registered User
 
Join Date: Mar 2003
Posts: 86
Are statistics updated? What happens to the plan if you:

runstats on table <schema>.L_CONSULTING with distribution and detailed indexes all;
runstats on table <schema>.L_CUSTOMER with distribution and detailed indexes all;
Reply With Quote
  #6 (permalink)  
Old 01-05-12, 03:43
amitrai4 amitrai4 is offline
Registered User
 
Join Date: Aug 2011
Posts: 46
Quote:
Originally Posted by db2girl View Post
Can you explain why hash join cannot use indexes?
That's the way hashing algorithm works.
www.devx.com/assets/ibm/3145.pdf
From the doc:
"The inner table (called the build table) is scanned first, and the rows are copied into memory buffers. These buffers are divided into partitions based on a “hash code,” which is computed from the column(s) in the join predicate(s).
Then the outer table (called the probe table) is scanned. For each row in the probe table the same hash algorithm is applied to the join column(s). If the hash code obtained matches the hash code of an build row, the
actual join columns are compared."

There are many things that may influence optimizer's decision to choose a particular join method. Take a look at above mentioned pdf, I find it quite informative.
Reply With Quote
  #7 (permalink)  
Old 01-05-12, 07:29
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
The scanning of the data could actually be an index scan if suitable. So an index would be used, although not for the actual join itself because the sorting of the index doesn't provide much benefits.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #8 (permalink)  
Old 01-05-12, 08:07
fengsun2 fengsun2 is offline
Registered User
 
Join Date: Nov 2011
Posts: 124
Quote:
Originally Posted by db2girl View Post
Can you explain why hash join cannot use indexes?
Because
1、There is no local predicate ,so db2 have to scan all rows ......
2、HSjoin need not to sort data,so it can't benifit from the sorted data of indexes.
3、the INDEX IDX_L_CONSULTING_CCCUSTID and L_CUSTOMER_PK does not cover the selected column so db2 can not use index only access to do index hash join .......

Last edited by fengsun2; 01-05-12 at 08:12.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On