io_stall_read_ms的值似乎高于查询的实际运行时间。设置:
create database filestats;
use filestats;
create table t1_primary(
a int identity
,b int
,c datetime
,d char(780)
,constraint pk_p_a primary key clustered (a));
set nocount on;
declare @n int = 0;
while @n < 12800
begin
insert into t1_primary select @n, CURRENT_TIMESTAMP, ABS(CHECKSUM(NEWID()))
select @n += 1
end
set statistics io, time on;
declare @before datetime
dbcc dropcleanbuffers
checkpoint
if object_id('tempdb..#vfsBefore') is not null
drop table #vfsBefore
if object_id('tempdb..#vfsAfter') is not null
drop table #vfsAfter
select *
into #vfsBefore
from sys.dm_io_virtual_file_stats(db_id('filestats'), null)
select @before = CURRENT_TIMESTAMP
select * from dbo.t1_primary
select DATEDIFF(ms, @before, CURRENT_TIMESTAMP)
select *
into #vfsAfter
from sys.dm_io_virtual_file_stats(db_id('filestats'), null)
select
db_name(b.database_id)
,mf.name
,a.num_of_reads-b.num_of_reads as NumReads
,a.num_of_bytes_read-b.num_of_bytes_read as NumBytesRead
,a.io_stall_read_ms-b.io_stall_read_ms as IOStallReadMS
,a.num_of_writes-b.num_of_writes as NumWrites
,a.num_of_bytes_written-b.num_of_bytes_written as NumBytesWritten
,a.io_stall_write_ms-b.io_stall_write_ms as IOStallWriteMS
,a.io_stall-b.io_stall as IOStallTotal
,a.size_on_disk_bytes-b.size_on_disk_bytes as SizeOnDiskBytes
,mf.physical_name
from #vfsBefore b
join #vfsAfter a on b.database_id = a.database_id and b.file_id = a.file_id
join sys.master_files mf on b.database_id = mf.database_id and b.file_id = mf.file_id
运行此结果会产生以下结果:
虚拟文件统计信息: num_of_reads = 26,io_stall_read_ms = 2153
统计IO:表't1_primary'。扫描计数1,逻辑读取2571,物理读取3,预读读取2552
统计时间: CPU时间= 46毫秒,已用时间= 595毫秒。
运行时间,DATEDIFF函数: 593 ms
毫不奇怪,执行聚簇索引扫描,单线程。为什么io_stall_read_ms值高于执行查询的时间。这是怎么回事?
可能是2153(io_stall_ms)/ 26(num_reads)= ~83ms每次读取操作停止吗?
此致
戈德