I am using SQL Server 2005.
I was coding with a friend of mine and just for an example I went to cast a join on the left side.
JOIN t on cast(a.foo as int) = b.foo
He told me never to do this as I loose all the performance benefits of indexing.
Why would you ever want to intentionally do this?
Well… The answer is sort of what your friend said. If you cast it, it won’t be able to take advantage indices on a.foo. However if you cast the right side then you won’t be able take advantage of indices on b.foo.
In the end, if you’re joining mismatched data types you’re going to have to lose somewhere. Whether it should be on the left or right hand side of a join depends entirely on the data density, and what indices are actually on the tables involved(e.g. It really doesn’t cost a whole lot if a.foo isn’t indexed anyway).