HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlModerate

How to re-enable read ahead (prefetch) feature in SQL Server after disabling it?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
afterenablereadsqlprefetchhowserverdisablingaheadfeature

Problem

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!

Solution

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.

Code Snippets

DBCC TRACEOFF (652, -1);
DBCC TRACEON (652);
...
...tests
....
DBCC TRACEOFF (652);

Context

StackExchange Database Administrators Q#140784, answer score: 13

Revisions (0)

No revisions yet.