Are these 2 sql queries equivalent in all respects (e.g. estimated and actual execution plan)?
- by Xerion
Are query 1) == 2) in terms of estimated query plan AND actual plan? (can statistics affect the actual plan here, ever?)
declare @cat int -- input param from prc
...
1)
select *
from A as a
join B as b
on b.id = a.id
on b.cat = @cat
join C as c
on c.fid = b.fid
on c.cat = @cat
where a.cat = @cat
2)
select *
from A as a
join B as b
on b.id = a.id
on b.cat = a.cat
join C as c
on c.fid = b.fid
on c.cat = b.cat
where a.cat = @cat
It seems to me that these should logically be equivalent and the execution plan should always be the same regardless of actual difference in tables. And adding more conditions either in join, or where, or add more tables to join shouldn't change this.
Are there cases this is not true?