Truusvlugindewind
Programmer
Given a hypotetical query
or you could code the same query
Notice the diff.? In the 1st example I code in the "JOIN ON" clause all the conditions to join the table in the select.
In the second I only code in the "JOIN ON" all the referential contraints on which the table is joined.
In the "WHERE" clause I code all the "external" conditions which must be met to include the rows.
DB2 should not give a damn. It will generate a perfect access plan for both situations. Fine.
But we humble humans? What is better/easier to write/maintain? I have not figured it out for myself yet. Please share your opinion.
Code:
select a.A1
, a.A2
, b.B1
, c.C9
, d.D8
from tabA a
join tabB b on b.B3 = a.A3
join tabC c on c.C2 = b.B2
and c.C4 in ( 1 , 6 , 8 , 9 )
and c.C8 = :hostC8
join tabD d on d.D1 = c.C1
and d.D5 < CURRENT DATE
where a.A5 = :hostA5
and a.A6 in ( 'a' , ' ')
Code:
select a.A1
, a.A2
, b.B1
, c.C9
, d.D8
from tabA a
join tabB b on b.B3 = a.A3
join tabC c on c.C2 = b.B2
join tabD d on d.D1 = c.C1
where a.A5 = :hostA5
and a.A6 in ( 'a' , ' ')
and c.C4 in ( 1 , 6 , 8 , 9 )
and c.C8 = :hostC8
and d.D5 < CURRENT DATE
In the second I only code in the "JOIN ON" all the referential contraints on which the table is joined.
In the "WHERE" clause I code all the "external" conditions which must be met to include the rows.
DB2 should not give a damn. It will generate a perfect access plan for both situations. Fine.
But we humble humans? What is better/easier to write/maintain? I have not figured it out for myself yet. Please share your opinion.