View previous topic :: View next topic
|
Author |
Message |
vinay_care
New User
Joined: 22 Sep 2006 Posts: 17
|
|
|
|
HI,
I have a simple query retrieving all the records using a cursor from a particular table without a where clause. ex:
EXEC SQL DECLARE STORE-CURSOR CURSOR WITH HOLD FOR
SELECT STORE,
COUNTRY_CODE
CLIMATE_CODE,
FROM STORE
END-EXEC.
and followed by relevant fetch and close cursor.
The table is indexed on STORE KEY,
what I want to know is, ---Does it makes any sense or improves the performance using additional where clause, and what where clause am I suppose to use and how?
As such the query is taking a long time. Plz do SUGGEST. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
impossible to reply without knowing the underlaying business/application requirements/specifications.
regards
e.s |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If the requirement is to process every row in the table, the time it will take will vary with the volume of data in the table. What is the indication that this needs "tuning"?
If you post the actual requirement (not the existing query), we may be able to offer suggestions. |
|
Back to top |
|
|
vijikesavan
Active User
Joined: 04 Oct 2006 Posts: 118 Location: NJ, USA
|
|
|
|
Hi,
As everyone said, its really difficult to give you the solution you are looking for.
I faced something like this before. If you want to select all the rows in the table, you can try one of these options
1) Check if there is any BMC or unload copies already exists for the table. You can use the file as input instead of making DB2 calls.
2) Sometimes just a rebind of the program or re-org of the table might help.
3) Try adding where clause or any new indexes after discussing with your DBA, business and other ppl who knows the application.
These are general tips for you to try, not sure of the results.
Thanks,
Viji |
|
Back to top |
|
|
wanderer
Active User
Joined: 05 Feb 2007 Posts: 199 Location: Sri Lanka
|
|
|
|
Yes, it will improve performance using WHERE clause with STORE KEY.
But then, if you need to see all the rows in table anyway, you can't use WHERE clause. |
|
Back to top |
|
|
prasadvrk
Active User
Joined: 31 May 2006 Posts: 200 Location: Netherlands
|
|
|
|
Quote: |
Does it makes any sense or improves the performance using additional where clause, and what where clause am I suppose to use and how?
|
Do not confuse between performance and desired result. Performance tuning should not change the result. Getting the same result in less time or consuming less resources is performance improvement. If you have selection criteria, why did you not use in the first place. |
|
Back to top |
|
|
TG Murphy
Active User
Joined: 23 Mar 2007 Posts: 148 Location: Ottawa Canada
|
|
|
|
Your SQL is so simple that I fear there's nothing much you can do.
When we need to tune an SQL statement, it generally looks like a monster. For example, 8 table joins with correlated subqueries. It can take hours to analyse the SQL - examine the EXPLAIN access path - consider alternatives.
When I look at your SQL it takes me about 2 seconds to conclude that not much can be done to the SQL itself to improve on things. Any improvements will have to come - as was recommened above - by tweaking the data (ie. reorg or purging dead data). |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
To repeat
Quote: |
What is the indication that this needs "tuning"?
|
|
|
Back to top |
|
|
vinay_care
New User
Joined: 22 Sep 2006 Posts: 17
|
|
|
|
vijikesavan wrote: |
Hi,
As everyone said, its really difficult to give you the solution you are looking for.
I faced something like this before. If you want to select all the rows in the table, you can try one of these options
1) Check if there is any BMC or unload copies already exists for the table. You can use the file as input instead of making DB2 calls.
2) Sometimes just a rebind of the program or re-org of the table might help.
3) Try adding where clause or any new indexes after discussing with your DBA, business and other ppl who knows the application.
These are general tips for you to try, not sure of the results.
Thanks,
Viji |
Thanks for the info.
we have a particular set of jobs which are taking a longer duration of time, when analysing further with certain tool we get to know what is causing the delay in time, and one such is above query,
certain times even after using certain keys in the where clause with index set will also take a longer run due to excess data, for those do we have any method that we can restrict those jobs for a lesser time? how would we fine tune such query?
Cheers,
vinay |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If your requirement is to use all of the rows in a table, there is not much to tune within the database.
If you have many millions of rows, you might unload the data and run your process(es) sequentially and not read the data via sql.
There is no way to define one or more new keys to speed up a full traversal.
It would be a good idea to test how long the unload/sequential run would take versus using sql. If the times are even similar, you might want to use the sequential appraoch as it could remove the unacceptable amount of processing from db2 and make other processes run better by reducing the impact of this large process. |
|
Back to top |
|
|
|