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
 

 

Time taken for execution of SQL Query in DB2 program

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Time taken for execution of SQL Query in DB2 program
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

Site Director


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

PostPosted: Mon Dec 03, 2007 8:58 pm    Post subject:
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    Post subject: Re: Time taken for execution of SQL Query in DB2 program
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: 149
Location: Ottawa Canada

PostPosted: Mon Dec 03, 2007 9:42 pm    Post subject:
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: 788
Location: Chennai, India

PostPosted: Mon Dec 03, 2007 9:49 pm    Post subject:
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    Post subject: Reply to: Time taken for execution of SQL Query in DB2 progr
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    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 Writing a file using online program grvtomar PL/I & Assembler 3 Fri Jun 30, 2017 1:06 pm
No new posts pre-compiler for program in an HFS Pedro DB2 0 Fri Jun 23, 2017 11:13 pm
No new posts Compiling program in endeavor for tra... RALAKKAL Compuware & Other Tools 4 Mon Jun 05, 2017 8:27 pm
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts COBOL DB2 program - zIIP eligible vasanthz COBOL Programming 7 Wed May 31, 2017 5:12 am


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