Are these 2 sql queries equivalent in all respects (e.g. estimated and actual execution plan)?
Posted
by Xerion
on Stack Overflow
See other posts from Stack Overflow
or by Xerion
Published on 2010-01-15T16:35:03Z
Indexed on
2010/03/15
17:09 UTC
Read the original article
Hit count: 181
sql
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?
© Stack Overflow or respective owner