The optmizer might do a join elimination when it's not changing the result set.
There are two issues with your approach:
#1: It must be a join to a UNIQUE/PK column.
In your case this is not known by the optmizer (indicated by the increasing estimated number of rows in each step).
#2: There must be an Outer Join or a Foreign Key.
Your view results in an Inner Join due to the WHERE condition on a1.PART and a2.PART.
To fix it you should define (PART, KEY) as UNIQUE and move a1.PART='01' and a2.PART='02' into the ON condition.
Dieter
↧