Unix Technical Forum

Table scans for larger rowcounts?

This is a discussion on Table scans for larger rowcounts? within the DB2 forums, part of the Database Server Software category; --> DB2 7.2 (7.1.0.68) on AIX 5.2. I have a query that does a table scan on one database, and ...


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-26-2008, 06:56 PM
Bruce Pullen
 
Posts: n/a
Default Table scans for larger rowcounts?

DB2 7.2 (7.1.0.68) on AIX 5.2.

I have a query that does a table scan on one database, and an index
scan on another.

The statistics on both databases are up-to-date. Indexes are
identical. Only rowcounts for one of the tables vary (it's using the
index where the table has 1,000 rows, but not where it has 10,000
rows).

Can anyone shed any light on why the optimiser's not picking up the
index consistently?

Here's the offending SQL if helpful:

SELECT MSG.MSG_Q_ID
FROM GFX.VU_INTRL_MSG_Q MSG,
GFX.VU_INTRL_MSG M
WHERE (
( MSG.MEMB_ID = 500000 AND
MSG.REGN_ID IS NULL ) OR
MSG.REGN_ID IN ( SELECT USR.REGN_ID
FROM GFX.VR_USR_ROUTE USR
WHERE USR.REGN_ID = MSG.REGN_ID
AND USR.MEMB_ID = 500000
AND USR.USR_ID =
18006554984185 ) )
AND M.MSG_ID = MSG.MSG_ID
AND ( 'B' IS NULL OR
LOCATE( COALESCE( MSG.MSG_TYPE, M.MSG_TYPE ),
'B' ) > 0 )
AND ( 'DAN' IS NULL OR
LOCATE( M.MSG_CATGY, 'DAN' ) > 0 )
AND ( ( 'A' = 'A' )
OR ( 'A' = 'U'
AND MSG.OWN_USR_ID IS NULL )
OR ( 'A' = 'Y'
AND MSG.OWN_USR_ID IN (SELECT USR_ID
FROM GFX.VU_USR
WHERE
rtrim(UPPR_FULL_NAME) like (rtrim (translate (UCASE ('DAN'), '%',
'*'))) ) )
OR ( 'A' = 'N'
AND MSG.OWN_USR_ID IN (SELECT USR_ID
FROM GFX.VU_USR
WHERE
UPPR_FULL_NAME = ( UCASE('DAN') ) ) )
OR ( 'A' = 'M'
AND MSG.OWN_USR_ID = 18006554984185 )
)
ORDER BY MSG.CRTD_TSTMP DESC
;

Thank you
Bruce
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-26-2008, 06:56 PM
AK
 
Posts: n/a
Default Re: Table scans for larger rowcounts?

are the cluster factors identical?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-26-2008, 06:56 PM
Bruce Pullen
 
Posts: n/a
Default Re: Table scans for larger rowcounts?

No, but those indexes with lower cluster ratios are being scanned?!?

INDNAME CLUSTERFACTOR
------------------ ------------------------
XAK1INTRL_MSG_Q +1.00000000000000E+000*
XIE1INTRL_MSG_Q +9.99159663865546E-001*
XIF11168AINTRLMSGQ +1.00000000000000E+000
XIF11168BINTRLMSGQ +7.77310924369748E-001
XIF1196INTRL_MSG_Q +8.84033613445378E-001
XIF1265INTRL_MSG_Q +7.77310924369748E-001
XPKINTRL_MSG_Q +1.00000000000000E+000

INDNAME CLUSTERFACTOR
------------------ ------------------------
XAK1INTRL_MSG_Q +9.80784161490683E-001
XIE1INTRL_MSG_Q +9.99320652173913E-001
XIF11168AINTRLMSGQ +9.80784161490683E-001
XIF11168BINTRLMSGQ +6.24805900621118E-001
XIF1196INTRL_MSG_Q +7.69701086956522E-001
XIF1265INTRL_MSG_Q +6.34025621118012E-001
XPKINTRL_MSG_Q +9.80784161490683E-001

*Those indexes being scanned.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-26-2008, 06:57 PM
AK
 
Posts: n/a
Default Re: Table scans for larger rowcounts?

well, the cluster factors are almost identical.
what about the percentage of rows that satisfy the criteria?

For instance, if the query uses an index and returns 50 rows out of 1K
(0.5%), using an index is justified.
If the same query scans the 10K table and returns 8500 rows out of 10K
(85%), that optimizer's choice to scan the table also makes perfect
sense
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-26-2008, 06:58 PM
Bruce Pullen
 
Posts: n/a
Default Re: Table scans for larger rowcounts?

The query I'm using returns 0 record(s) selected on both databases.
I'm thinking maybe this has something to do with IO / tablespace
container configuration, just not sure how to confirm this. Any tips
much appreciated.
Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-26-2008, 06:59 PM
AK
 
Posts: n/a
Default Re: Table scans for larger rowcounts?

you might also want to use OPTIMIZE FOR FIRST and / or SELECTIVITY
clause
that might influence the optimizer to choose the index.
Then you could compare real execution costs and see if choosing the
index what the right thing to do
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:55 AM.


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