NOLOCK is not a turbo button

All to often when talking to developers they put the WITH (NOLOCK) table hint in place to speed up queries without understanding what the table hint does.  I’ve even run across companies that have policies in place that every select statement must have the WITH (NOLOCK) table hint.

The WITH (NOLOCK) table hint isn’t a go faster button for SQL Server.  It has actual implications to the data which is being returned by the query.  The biggest of these implications is that the data might not be correct.  You see the WITH (NOLOCK) table hint uses dirty reads to return the data, so it basically ignores the locks which other queries have taken.  This is why the query appears to run faster, because the query isn’t being blocked any more.  The proper approach would be to find the query which is causing the extended blocking and figure out why it is taking so long to run, and fix the performance problems of that query.

The only go faster button that is available in SQL Server is the CREATE INDEX statement.  Anything else isn’t truly a go faster button, and has other side effects which must be understood before being implemented.



One Response

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trust DCAC with your data

Your data systems may be treading water today, but are they prepared for the next phase of your business growth?