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

COL op expression


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

New User


Joined: 06 Feb 2006
Posts: 17
Location: Kolkata

PostPosted: Mon Sep 13, 2010 7:05 pm
Reply with quote

Hi,
I have a query in a program in which is having col1+col2 > 0 in the where clause. I am converting it to WHERE col1 > col2 * -1. Its giving me some performance gain.
col1 + col2 > 0 is a Stage 2 Predicate. Can ua please let me know the reason for the CPU gain. is col1 > col2 * -1 Stage 1 ? Converting from Stage 2 to Stage 1 is giving the gain ?

Another thing... Can u please share with me any further SQL tuning tips ? We are working on a performance tuning project using COBOL-CICS-DB2.

Thanks,
Tamal
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Mon Sep 13, 2010 7:37 pm
Reply with quote

afaik Col1 > col2 is still stage2 when col1 and col2 are from the same table.

What tool do you use to explain? OSC will tell you if it is stage 1 or Stage2.

If you have a full set of explain_tables following query will also tell you :
Code:
select a.PROGNAME, a."QUERYNO",a."VERSION", B.SEARCHARG, b.text from
plan_table A
join DSN_PREDICAT_TABLE B
on a."QUERYNO" = b."QUERYNO" and a.BIND_TIME = b.EXPLAIN_TIME

where A.PROGNAME = ?
 and a."VERSION" = ?
 and a."QUERYNO" = ?
Back to top
View user's profile Send private message
tamal_babu

New User


Joined: 06 Feb 2006
Posts: 17
Location: Kolkata

PostPosted: Mon Sep 13, 2010 11:03 pm
Reply with quote

COL1 AND COL2 are from the same table. Please lemme know if there is any other way to remove this kind of stage 2 predicate and make it stage 1 ?

WHERE COL1 + COL2 > 0
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1056
Location: Richmond, Virginia

PostPosted: Tue Sep 14, 2010 1:00 am
Reply with quote

Just asking: would COL1 > -COL2 be the same or better than the version with "* -1"?
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Tue Sep 14, 2010 11:03 am
Reply with quote

tamal_babu wrote:
COL1 AND COL2 are from the same table. Please lemme know if there is any other way to remove this kind of stage 2 predicate and make it stage 1 ?

WHERE COL1 + COL2 > 0


Code:
(Col1 > 0 OR Col2 > 0)
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Tue Sep 14, 2010 3:42 pm
Reply with quote

1) col1 + col2 > 0 is equivalent to col1 > 0 or col2 > 0 ONLY if both are always positive (or always negative)

2) performance of unary - is probably picoseconds faster than * -1

3) from TAB1 where col1 = -col2 is stage2
you can change it to stage1 but it is not always better, but worth a try:
from TAB1 A, TAB1 B where a.pk = b.pk and a.col1 = -b.col2
Back to top
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Cobcalc: An Algebraic Expression Eval... COBOL Programming 10
No new posts Clustered Index with UCASE Key Expres... DB2 2
No new posts V9 - Expression indices DB2 2
No new posts CASE Expression with Multiple Entries DB2 8
No new posts CASE Expression DB2 5
Search our Forums:


Back to Top