Unix Technical Forum

Tablescan - why?

This is a discussion on Tablescan - why? within the DB2 forums, part of the Database Server Software category; --> I have a problem with simple query like this (PK - Primary key) select t1.*, t2.col1, t3.col2 from T1 ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 07:06 AM
bughunter@ru
 
Posts: n/a
Default Tablescan - why?

I have a problem with simple query like this (PK - Primary key)

select t1.*, t2.col1, t3.col2
from
T1
inner join T2 on T2.PK = T1.col1
inner join T3 on T3.PK = T2.col1

T1 is very small table ~20-30 rows, T2 and T3 large. In query plan and
monitor output I see table scan on T3. Why?

Index T2_PK has included column col1.


Access Plan:
-----------
Total Cost: 43603.2
Query Degree: 1

Rows
RETURN
( 1)
Cost
I/O
|
3092
HSJOIN
( 2)
43602.9
10783
/------+------\
227641 3092
TBSCAN NLJOIN
( 3) ( 4)
40666.2 2926.35
10361 422.045
| /---+---\
227641 3092 1
TABLE: S TBSCAN IXSCAN
T3 ( 5) ( 8)
406.107 50.016
100 2
| |
3092 64931
SORT INDEX: S
( 6) T2_PK
406.107
100
|
3092
TBSCAN
( 7)
404.727
100
|
3092
TABLE: S
T1


Andy

P.S. UDB 8.2 FP10 win32

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 07:06 AM
Hardy
 
Posts: n/a
Default Re: Tablescan - why?

hey, do you have any index on T3? if not how can they be used?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 07:07 AM
bughunter@ru
 
Posts: n/a
Default Re: Tablescan - why?

watch closely! PK - primary key - always have a unique index. I'm try
also create index like (PK) include (col2) because this column used in
select - without success.

Andy

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

bughunter@ru wrote:
> watch closely! PK - primary key - always have a unique index. I'm try
> also create index like (PK) include (col2) because this column used in
> select - without success.
>
> Andy
>

This does look odd.
Making T1 the outer and probing T2 and T3 using the PKs is obviously the
better 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
  #5 (permalink)  
Old 02-27-2008, 07:07 AM
Tonkuma
 
Posts: n/a
Default Re: Tablescan - why?

What are column attributes?
Would you show us your DDLs?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-27-2008, 07:08 AM
bughunter@ru
 
Posts: n/a
Default Re: Tablescan - why?

DDL is simple like

T1
(DEALID INTEGER NOT NULL, -- PK
APPLID INTEGER NOT NULL, -- T1.Col1
..... -- ~10 short columns like date, dec, int)

T2 (
APPLID INTEGER NOT NULL, -- PK
STOCKID CHARACTER(4) NOT NULL, -- T2.Col1
..... -- ~20 short columns like timestamp, dec, int, char)

T3 (
STOCKID CHARACTER(4) NOT NULL, -- PK
CRDDATE DATE NOT NULL, -- T3.Col1
..... -- ~20 short columns like timestamp, dec, int, char)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-27-2008, 07:08 AM
Knut Stolze
 
Posts: n/a
Default Re: Tablescan - why?

bughunter@ru wrote:

> DDL is simple like
>
> T1
> (DEALID INTEGER NOT NULL, -- PK
> APPLID INTEGER NOT NULL, -- T1.Col1
> .... -- ~10 short columns like date, dec, int)
>
> T2 (
> APPLID INTEGER NOT NULL, -- PK
> STOCKID CHARACTER(4) NOT NULL, -- T2.Col1
> .... -- ~20 short columns like timestamp, dec, int, char)
>
> T3 (
> STOCKID CHARACTER(4) NOT NULL, -- PK
> CRDDATE DATE NOT NULL, -- T3.Col1
> .... -- ~20 short columns like timestamp, dec, int, char)


What's the data you have in there and what's your query?

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-27-2008, 07:08 AM
miro
 
Posts: n/a
Default Re: Tablescan - why?

According to your explain output below DB2 seems to believe that there
are 3092 rows in table T1. You seem to think T1 is much smaller. Have
you ran runstats recently? If the size of T1 in the plan explain below
is correct, and if the index on T3_PK is not a clustering one, then it
might actually be cheaper to do the join like shown below (build the
hash table based on the result of T1 join T2, the probe it with rows
from T3).

Regards,
Miro

bughunter@ru wrote:
> I have a problem with simple query like this (PK - Primary key)
>
> select t1.*, t2.col1, t3.col2
> from
> T1
> inner join T2 on T2.PK = T1.col1
> inner join T3 on T3.PK = T2.col1
>
> T1 is very small table ~20-30 rows, T2 and T3 large. In query plan and
> monitor output I see table scan on T3. Why?
>
> Index T2_PK has included column col1.
>
>
> Access Plan:
> -----------
> Total Cost: 43603.2
> Query Degree: 1
>
> Rows
> RETURN
> ( 1)
> Cost
> I/O
> |
> 3092
> HSJOIN
> ( 2)
> 43602.9
> 10783
> /------+------\
> 227641 3092
> TBSCAN NLJOIN
> ( 3) ( 4)
> 40666.2 2926.35
> 10361 422.045
> | /---+---\
> 227641 3092 1
> TABLE: S TBSCAN IXSCAN
> T3 ( 5) ( 8)
> 406.107 50.016
> 100 2
> | |
> 3092 64931
> SORT INDEX: S
> ( 6) T2_PK
> 406.107
> 100
> |
> 3092
> TBSCAN
> ( 7)
> 404.727
> 100
> |
> 3092
> TABLE: S
> T1
>
>
> Andy
>
> P.S. UDB 8.2 FP10 win32
>

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 01:41 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com