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
 

 

Alternate for 'distinct' in db2 query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Alternate for 'distinct' in db2 query
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: 6968
Location: porcelain throne

PostPosted: Thu Jun 04, 2009 3:51 pm    Post subject:
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    Post subject:
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: 6968
Location: porcelain throne

PostPosted: Thu Jun 04, 2009 5:35 pm    Post subject:
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    Post subject:
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    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 Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
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


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