Unix Technical Forum

Optimizing Query

This is a discussion on Optimizing Query within the DB2 forums, part of the Database Server Software category; --> Can anybody tell me how to improve the performance of this query? SELECT NID, LEVEL, VALUE FROM DATA WHERE ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-26-2008, 10:16 AM
Erwin
 
Posts: n/a
Default Optimizing Query

Can anybody tell me how to improve the performance of this query?

SELECT
NID, LEVEL, VALUE
FROM
DATA
WHERE
DID=2 AND STATUS=0

The value of STATUS is either 0 or 1. The primary key of DATA is EID
which I don't use in the query.

The total cost of the query without index is 240.47
If I put index on DID and STATUS, the total cost is 190.47.

Thanks

Erwin
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-26-2008, 10:16 AM
Joerg Ammann
 
Posts: n/a
Default Re: Optimizing Query

erwin2@myrealbox.com (Erwin) wrote in message news:<43ecf6d7.0308130142.3091870d@posting.google. com>...
> Can anybody tell me how to improve the performance of this query?
>
> SELECT
> NID, LEVEL, VALUE
> FROM
> DATA
> WHERE
> DID=2 AND STATUS=0
>
> The value of STATUS is either 0 or 1. The primary key of DATA is EID
> which I don't use in the query.
>
> The total cost of the query without index is 240.47
> If I put index on DID and STATUS, the total cost is 190.47.
>
> Thanks
>
> Erwin


datatype of STATUS ?
did you a
runstats WITH DISTRIBUTION
on the table?, otherwise the optimizer does not know that there are
only 2 different values for STATUS.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-26-2008, 10:16 AM
Erwin
 
Posts: n/a
Default Re: Optimizing Query

> datatype of STATUS ?

I use SMALLINT. Actually, I need only two values for STATUS.

> did you a
> runstats WITH DISTRIBUTION
> on the table?, otherwise the optimizer does not know that there are
> only 2 different values for STATUS.


I didn't execute RUNSTATS WITH DISTRIBUTION on the table. I try to
execute RUNSTATS WITH DISTRIBUTION, and it works.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

« test | Best way »

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 10:38 AM.


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