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
FROM TABLE_ X
the modified query details are:
SELECT A, B
FROM TABLE_ X
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)
Joined: 20 Oct 2006 Posts: 6970 Location: porcelain throne
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.
the status of the table (large/small, reorg'd, bind with latest statistics),
activity in machine,
amount of iron,
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.
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.