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
 

 

BETWEEN Versus > and < in DB2 SQL Query - Performance

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
chinnielr

New User


Joined: 11 Jul 2005
Posts: 87

PostPosted: Thu Jul 10, 2008 1:14 pm    Post subject: BETWEEN Versus > and < in DB2 SQL Query - Performance
Reply with quote

Hi All,

I have the following querys:

SELECT ID, ADDRESS
FROM EMPLOYEE A
WHERE ID=12345
AND CURRENT DATE BETWEEN A.EFF_DT AND A.EXP_DT

SELECT ID, ADDRESS
FROM EMPLOYEE A
WHERE ID=12345
AND CURRENT DATE > A.EFF_DT AND CURRENT DATE < A.EXP_DT

Out of these two queries which query yields better performance.

Here I am using operators > and < instead of BETWEEN.

Please suggest.

Thanks,
Chinni.
Back to top
View user's profile Send private message

ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Thu Jul 10, 2008 2:59 pm    Post subject:
Reply with quote

Do an EXPLAIN on your query and see the o/p in PLAN_TABLE and DSN_STATEMNT_TABLE ...
BETWEEN is usually more efficient than <= predicate and the >= predicate
Except when comparing a host variable to 2 columns

I guess this concept was bought in DB2 versions after version 6 ... bfore that > and < used to perform better ... i read this in some blog by craigmullins ...
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jul 10, 2008 3:12 pm    Post subject:
Reply with quote

Quote:

Out of these two queries which query yields better performance


Performance is not your worry, accuracy is.

BETWEEN, as ashimer said, is =< =>, NOT < and >.

so, you do not want to use between.
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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts BC, BCR, BRC, BRCL performance steve-myers PL/I & Assembler 0 Fri Dec 23, 2016 7:44 am
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am


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