I'm joining two tables on a composite key, and I'm wondering if it matters where I compare the corresponding columns when I do the join.
Say I have a table, TableA, with columns ColAFoo, ColAFoo2, and ColABar. TableA has a composite primary key comprising ColAFoo and ColAFoo2 (PK_TableA).
I also have TableB, with ColBFoo, ColBFoo2, and ColBOther. TableB's columns ColBFoo and ColBFoo2 comprise a foreign key to TableA's primary key (FK_TableA_TableB).
I need to join the two tables on the key. Is there a difference between the following three (extraordinarily contrived) statements in terms of performance?
SELECT *
FROM TableA a
JOIN TableB b
ON a.ColAFoo = b.ColBFoo
AND a.ColAFoo2 = b.ColBFoo2
SELECT *
FROM TableA a
JOIN TableB b
ON a.ColAFoo = b.ColBFoo
WHERE a.ColAFoo2 = b.ColBFoo2
-- this one is a little /too/ contrived, apparently (see comments)
SELECT *
FROM TableA a
JOIN TableB b
WHERE a.ColAFoo = b.ColBFoo
AND a.ColAFoo2 = b.ColBFoo2