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

Time taken for execution of SQL Query in DB2 program


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

New User


Joined: 03 Dec 2007
Posts: 7
Location: Mumbai

PostPosted: Mon Dec 03, 2007 4:35 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Dec 03, 2007 8:58 pm
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Mon Dec 03, 2007 9:19 pm
Reply with quote

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
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 148
Location: Ottawa Canada

PostPosted: Mon Dec 03, 2007 9:42 pm
Reply with quote

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
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Mon Dec 03, 2007 9:49 pm
Reply with quote

I think 2nd query will run faster than first query. Because in 2nd query DATA2, DATA3 and DATA4 are colunms used for restricting the fetching. And I assume those 3 colums are indexes.

You can use EXPLAIN PLAN to get the details for Execution.

You please visit this link for DB2 tuning.

http://www.ibm.com/developerworks/db2/library/techarticle/dm-0404mcarthur/index.html

Correct me if I am wrong.
Back to top
View user's profile Send private message
arultm

New User


Joined: 03 Dec 2007
Posts: 7
Location: Mumbai

PostPosted: Tue Dec 04, 2007 9:37 am
Reply with quote

Hi
Thank you very much..
It is really helpful and will let you know how it is working after executing it..
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 Using API Gateway from CICS program CICS 0
No new posts To get the the current time DFSORT/ICETOOL 13
No new posts RC query -Time column CA Products 3
No new posts Capturing Job Execution Information All Other Mainframe Topics 3
No new posts C Compile time time stamps Java & MQSeries 10
Search our Forums:

Back to Top