|
View previous topic :: View next topic
|
| Author |
Message |
tamal_babu
New User
.jpg)
Joined: 06 Feb 2006 Posts: 17 Location: Kolkata
|
|
|
|
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 |
|
 |
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
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 |
|
 |
tamal_babu
New User
.jpg)
Joined: 06 Feb 2006 Posts: 17 Location: Kolkata
|
|
|
|
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 |
|
 |
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1056 Location: Richmond, Virginia
|
|
|
|
| Just asking: would COL1 > -COL2 be the same or better than the version with "* -1"? |
|
| Back to top |
|
 |
Bharath Bhat
Active User

Joined: 20 Mar 2008 Posts: 283 Location: chennai
|
|
|
|
| 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 |
|
 |
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
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 |
|
 |
|
|