Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
hw to fine tune query having distinct along with grouping?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
vinay_care

New User


Joined: 22 Sep 2006
Posts: 17

PostPosted: Tue Aug 14, 2007 4:28 pm    Post subject: hw to fine tune query having distinct along with grouping?
Reply with quote

Hi,

I have a query where in which its taking a longer CPU time, need to cut shot the execution time, the query goes like th's

CURSOR:
SELECT DISTINCT
STORE
, ITEM
, TRANS
, SUB_TRANS
, VEND
, VENDOR_NAME
, STORE_NAME
, STORE_INVDATE
, SUM (QTY)
FROM VIN_TRANSIT, VAZWHSE,
VAZVEND, SESSION.STRINVDATES
WHERE POS_TRANS =: P
AND POS_STORE = TAB_STORE_NBR
AND POS_ADD_CLEAR_DATE IS NULL
AND POS_ITEM = ITEM
AND WHSE = TAB_STORE_WHSE
AND VEND = VENDOR
AND POS_FLAG IN (:B, :Y)
GROUP BY POS_STORE, POS_ITEM, POS_TRANS, POS_SUB_TRANS,
VEND, VENDOR_NAME,
TAB_STORE_NAME, TAB_STORE_INVDATE
now since its grouping a set of variables and then finding the disticnt value its taking a longer time, please let me know hw could i fine tune above query or is anyway i can split the query but maintain the same end result?
plz suggest, let me know if its confusing.....

Cheers,
vinay
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Tue Aug 14, 2007 5:03 pm    Post subject:
Reply with quote

I imagine the fact that it is a 4 table join has more to do with the execution time than the distinct.

have you run an explain on the query? if not, do so.
Back to top
View user's profile Send private message
Prajesh_v_p

Active User


Joined: 24 May 2006
Posts: 133
Location: India

PostPosted: Tue Aug 14, 2007 5:03 pm    Post subject:
Reply with quote

Do an explain of the query..Check how index is being used.. Bring in more columns if possible to increse the index match in where clause..

Are u sure you need a distint cluse out there?.. Group by and sum fuction retrieves only sum for all distict values of columns selected. Since there are some diffrence in the select clause and group by clause..you need to check it out!

Qry seems a bit confusing as you have not used any alias and I am not sure which columns comes from which table..
Back to top
View user's profile Send private message
vinay_care

New User


Joined: 22 Sep 2006
Posts: 17

PostPosted: Tue Aug 14, 2007 6:10 pm    Post subject:
Reply with quote

Prajesh_v_p wrote:
Do an explain of the query..Check how index is being used.. Bring in more columns if possible to increse the index match in where clause..

Are u sure you need a distint cluse out there?.. Group by and sum fuction retrieves only sum for all distict values of columns selected. Since there are some diffrence in the select clause and group by clause..you need to check it out!

Qry seems a bit confusing as you have not used any alias and I am not sure which columns comes from which table..


I did do the explain but it shows scan being performed on tablespace and not on index
Back to top
View user's profile Send private message
Prajesh_v_p

Active User


Joined: 24 May 2006
Posts: 133
Location: India

PostPosted: Tue Aug 14, 2007 6:51 pm    Post subject:
Reply with quote

Vinay,

I am not clear on whats wrong with this as I dont have any info regarding the index and columns of the tables.. Can you provide these details also...
Back to top
View user's profile Send private message
vinay_care

New User


Joined: 22 Sep 2006
Posts: 17

PostPosted: Thu Aug 16, 2007 1:07 pm    Post subject:
Reply with quote

Apart from POS_FLAG all other fields are set with index
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Thu Aug 16, 2007 4:04 pm    Post subject:
Reply with quote

try changing from this:
Code:

...
 AND VEND = VENDOR
 AND POS_FLAG IN (:B, :Y)
GROUP BY POS_STORE, POS_ITEM, POS_TRANS, POS_SUB_TRANS,
VEND, VENDOR_NAME,
TAB_STORE_NAME, TAB_STORE_INVDATE

to this:
Code:

 AND VEND = VENDOR
GROUP BY POS_STORE, POS_ITEM, POS_TRANS, POS_SUB_TRANS,
VEND, VENDOR_NAME,
TAB_STORE_NAME, TAB_STORE_INVDATE
HAVING POS_FLAG IN (:B, :Y)
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts DFSORT - Overriding default option TU... Steve Ironmonger DFSORT/ICETOOL 3 Tue Apr 04, 2017 3:54 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us