Hi,
The following SQL:
Code:
SELECT A.DependentCol1, B.ParentCol1 FROM
DependentTable A LEFT OUTER JOIN ParentTable B
ON (A.DependentColFK = B.ParentColPK)
after reorg and runstats the above SQL uses 'table scan' (seeing from explain).
But adding a condition "AND B.ParentCol = COALESCE(B.ParentCol, B.ParentCol)" makes DB2 uses the 'index scan' which is in my case 3-times faster. Index is on column B.ParentColPK - this column is PK of ParentTable.
Target SQL looks like this:
Code:
SELECT A.DependentCol1, B.ParentCol1 FROM
DependentTable A LEFT OUTER JOIN ParentTable B
ON (A.DependentColFK = B.ParentColPK)
AND B.ParentCol = COALESCE(B.ParentCol, B.ParentCol)
Are there any general rules to enforce 'index scan' instread of 'table scan'? I am just looking is some general tips...
Thanks,
Grofaty