SQL Server – How to Re-enable Read Ahead (Prefetch) Feature After Disabling

sql server

In Microsoft SQL Server, I've disabled the read ahead (prefetch) feature using

    DBCC TRACEON(652,-1)

But does anyone know how to enable the read ahead feature?

Before I disabled the read ahead, using

    set statistics io on

I get this result:

    Scan count 1, logical reads 529, physical reads 4, read-ahead reads 1192

Now after disabling read ahead using the above DBCC query, I get this:

    Scan count 1, logical reads 44, physical reads 19, read-ahead reads 0

I'd like to be able to disable/enable the prefetch feature freely so I could compare among different queries. I googled everywhere but didn't find an answer for that… Anyone knows how to re-enable it? Thanks!

Best Answer

All you need do is turn the trace flag off globally:

DBCC TRACEOFF (652, -1);

A service restart is not required.

To control read-ahead for the current session only, simply omit the -1.

DBCC TRACEON (652);
...
...tests
....
DBCC TRACEOFF (652);

This trace flag is only minimally documented, so for anything more than educational purposes on an isolated test system, it makes sense to contact Microsoft Support for advice.

Note: QUERYTRACEON is not effective for trace flag 652.