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: 6970
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: 6970
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 How to query MAXGENS of an existing P... Chuchulo Hatyzak JCL & VSAM 4 Wed Nov 22, 2017 10:23 pm
No new posts Native SQL Query kishpra DB2 1 Wed Nov 22, 2017 8:38 pm
No new posts Query on IEFBR14 with GDG Ashishpanpaliya JCL & VSAM 4 Tue Nov 07, 2017 8:34 pm
No new posts Query on XMITIP abdulrafi All Other Mainframe Topics 1 Wed Oct 25, 2017 6:54 pm
No new posts HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm

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