Sample Header Ad - 728x90

A question on SARGability

11 votes
2 answers
207 views
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: 1. Indexes will not be used because of the manipulation of the column 2. The query plans will be different partly because of the above (not tested, assuming so) 3. Because of the above, the 1st query will actually perform worse than the 2nd. **My question:** Have I missed anything out in my reasoning? Am I correct? Lastly, does any body have any good articles on SARGability?
Asked by Stuart Blackler (4540 rep)
Aug 16, 2011, 08:14 PM
Last activity: Jul 30, 2013, 06:59 PM