View previous topic :: View next topic
|
Author |
Message |
arultm
New User
Joined: 03 Dec 2007 Posts: 7 Location: Mumbai
|
|
|
|
Hi,
If we use more conditions in WHERE clause to restrict number of rows to be fetched, will the execution of query take more time?
For ex.
1.)SELECT data1
FROM table
WHERE data2 = ‘V’
AND data3 = ‘101’
2.) SELECT data1
FROM table
WHERE data2 = ‘v’
AND data3 = ‘101’
AND data4 = ‘k’
While executing both the queries in a program using cursor, will 2nd query takes more time for execution when compared to 1st query?
Please clarify….
And please give some tips to use SQL query efficiently in the program... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello arultm and welcome to the forums,
Quote: |
If we use more conditions in WHERE clause to restrict number of rows to be fetched, will the execution of query take more time? |
It should not take more time.
Quote: |
While executing both the queries in a program using cursor, will 2nd query takes more time for execution when compared to 1st query? |
No.
Quote: |
And please give some tips to use SQL query efficiently in the program... |
Whenever possible, use columns that are indexed. Dependig on the type of queries, it is often necessary to add additional indexes to support the queries. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
arultm wrote: |
Hi,
1.)SELECT data1
FROM table
WHERE data2 = ‘V’
AND data3 = ‘101’
2.) SELECT data1
FROM table
WHERE data2 = ‘v’
AND data3 = ‘101’
AND data4 = ‘k’
While executing both the queries in a program using cursor, will 2nd query takes more time for execution when compared to 1st query?
Please clarify….
|
I am assuming that with the first cursor your program is checking data4, so what you have done is move some of the processing from your program to DB2. |
|
Back to top |
|
|
TG Murphy
Active User
Joined: 23 Mar 2007 Posts: 148 Location: Ottawa Canada
|
|
|
|
If your first query returns 10,000 rows and your second query reduces this to 500 rows then your second query should execute faster. Your COBOL program will do 500 fetches instead of 10,000.
The DBAs always answer these questions with "It all depends..." |
|
Back to top |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
Back to top |
|
|
arultm
New User
Joined: 03 Dec 2007 Posts: 7 Location: Mumbai
|
|
|
|
Hi
Thank you very much..
It is really helpful and will let you know how it is working after executing it.. |
|
Back to top |
|
|
|