I just need to confirm that I understand something correctly:
I recently viewed an SO question in which a user posted an answer in Linq like:
from p in db.table where p.column.AddMinutes(1) > DateTime.Now select p
To those unfamiliar with Linq, I would expect the output of that statement (not tested it in fairness) to be:
SELECT * FROM table t WHERE DATEADD(min, 1, t.column) >= GETDATE()
I posted an reply to this saying that the datetime manipulation should be on the variable (in this case
GETDATE()) so in fact the statement should reflect something like:
SELECT * FROM table t WHERE t.column >= DATEADD(min, -1, GETDATE())
In my reply, the bits i'm now unsure of, assume the following:
- Indexes will not be used because of the manipulation of the column
- The query plans will be different partly because of the above (not tested, assuming so)
- Because of the above, the 1st query will actually perform worse than the 2nd.
Have I missed anything out in my reasoning? Am I correct? Lastly, does any body have any good articles on SARGability?