IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Alternate for 'distinct' in db2 query


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
vinay ityala

New User


Joined: 07 Dec 2008
Posts: 5
Location: bangalore

PostPosted: Thu Jun 04, 2009 3:38 pm
Reply with quote

Hi,

In one of the job db2 query with 'distinct' was consuming lot of time and dollars, to reduce it I had used the fetch first row by commenting out distinct.

I ran Explain and saw that the changed query was giving veryless consumption, but the problem here is when iam running the job ,actually BAU (i.e distinct) with less number of records was completing first and the fetch first row changes were taking more time.

Pls let me know any other alternative can be used in place of 'distinct'

The existing query details are:

SELECT DISTINCT A, B
INTO DCLTABLE-X.A,
DCLTABLE-X.B
FROM TABLE_ X
WHERE A=
:DCLTABLE-X.A
AND B=
:DCLTABLE-X.B

the modified query details are:

SELECT A, B
INTO DCLTABLE-X.A,
DCLTABLE-X.B
FROM TABLE_ X
WHERE A=
:DCLTABLE-X.A
AND B=
:DCLTABLE-X.B
FECTH FIRST ROW ONLY

The values for the column A are received from i/p file and the SQL calls will be mainly depending on i/p file and the value for column 'B' will
be 2(before this query execution the value '2' will be moved to the column)

Let me know any other info is required.

Thanks a lot in advance.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Jun 04, 2009 3:51 pm
Reply with quote

Since B will always be 2, why select it?
Then the DISTINCT would only be for one column.
you could also GROUP by A instead of DISTINCT.

are column A and B in an INDEX?
Back to top
View user's profile Send private message
vinay ityala

New User


Joined: 07 Dec 2008
Posts: 5
Location: bangalore

PostPosted: Thu Jun 04, 2009 4:59 pm
Reply with quote

Hi,

Ur true, I had selected only one column -A and executed with group by, I had observed no differnce, still group by was also taking long time

The following is the query which I had executed now

SELECT A
INTO DCLTABLE-X.A,
FROM TABLE_ X
WHERE A=
:DCLTABLE-X.A
AND B=
:DCLTABLE-X.B
GROUP BY A

For Ur second question column 'A' was indexed.
Let me know if any othere altrnatives were there


Thanks a lot for Ur qucik response.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Jun 04, 2009 5:35 pm
Reply with quote

index col B?

you need to run an EXPLAIN against the SQL.
If you have vsn 7 (maybe 8) there is an extension of the explain
(it is in the manual)
which will give you the resource costs statistics (similar to qmf when you EXECUTE - PF6).

Also, have you reorg'd and runstats lately? That also means alot.

by the way, "it is taking a long time" is a really useless comment
unless you can provide DB2 generated consumption statistics on the query.
otherwise,
the status of the table (large/small, reorg'd, bind with latest statistics),
activity in machine,
amount of iron,
task priority
can affect the 'amount of time' a query takes.

I assume that this is imbedded SQL.

try running the query in spufi with explain.
also, it could be that using rowset, without a distinct or group by and
determining the distinct with code in the program could be faster.
Back to top
View user's profile Send private message
vinay ityala

New User


Joined: 07 Dec 2008
Posts: 5
Location: bangalore

PostPosted: Thu Jun 04, 2009 5:50 pm
Reply with quote

Hi,

Index was column 'A',

I mean it was taking a 'long time' in sense the production version with limited records( arund 50,000)was consuming around 0.23 dollars and for same records the changed query was taking around 8 dollars ..

do not misunderstand me...

I had ran the explain with the suggested query also, this was also showing very less consumption but again the same changes in the
program was creating more consumption.

Thanks a lot for your inputs
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top