Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 6966
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: 6966
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 JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm
No new posts GETMAIN/FREEMAIN query Suja.Sai CICS 9 Tue Jan 31, 2017 12:01 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us