在我的 SQL Server 中创建 tpch 数据库后,我尝试了以下查询:
set statistics io on
DBCC DROPCLEANBUFFERS;
select top 100 * from dbo.lineitem order by l_partkey;
Run Code Online (Sandbox Code Playgroud)
表 lineitem 在 l_partkey 上有一个非聚集索引。我多次发出上述查询,发现每次逻辑读取都不同:
Table 'lineitem'. Scan count 1, logical reads 1019, physical reads 4, read-ahead reads 1760, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'lineitem'. Scan count 1, logical reads 1007, physical reads 4, read-ahead reads 1720, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'lineitem'. …
Run Code Online (Sandbox Code Playgroud) 在 Microsoft SQL Server 中,我使用以下方法禁用了预读(预取)功能
DBCC TRACEON(652,-1)
Run Code Online (Sandbox Code Playgroud)
但是有人知道如何启用预读功能吗?
在我禁用预读之前,使用
set statistics io on
Run Code Online (Sandbox Code Playgroud)
我得到这个结果:
Scan count 1, logical reads 529, physical reads 4, read-ahead reads 1192
Run Code Online (Sandbox Code Playgroud)
现在在使用上面的 DBCC 查询禁用预读后,我得到了这个:
Scan count 1, logical reads 44, physical reads 19, read-ahead reads 0
Run Code Online (Sandbox Code Playgroud)
我希望能够自由禁用/启用预取功能,以便我可以在不同的查询之间进行比较。我到处搜索,但没有找到答案......有人知道如何重新启用它吗?谢谢!