I SQL Server kan du bruge SET STATISTICS IO
sætning for at generere detaljerede oplysninger om mængden af diskaktivitet, der genereres af en T-SQL-sætning.
I grafiske værktøjer som SSMS og Azure Data Studio kan du se disse oplysninger i Beskeder fanen.
Eksempel
Her er et simpelt eksempel at demonstrere.
SET STATISTICS IO ON;
SELECT
c.CityName,
s.StateProvinceName AS State,
c.LatestRecordedPopulation AS Population
FROM Application.Cities c
INNER JOIN Application.StateProvinces s
ON c.StateProvinceID = s.StateProvinceID
WHERE c.LatestRecordedPopulation > 2000000
ORDER BY c.LatestRecordedPopulation DESC;
I første omgang vil du sandsynligvis se forespørgselsresultaterne som sædvanligt:
For at se output fra STATISTICS IO
, klik på Beskeder fanen:
Dette eksempel blev udført i Azure Data Studio, og det er den samme proces, når du bruger SSMS. De faktiske trin, du skal bruge, kan dog afhænge af det værktøj, du bruger til at oprette forbindelse til SQL Server.
Nedenfor er en kopi af STATISTICS IO
besked fra ovenstående skærmbillede:
(6 rows affected) Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, page server reads 0, read-ahead reads 0, page server read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob page server reads 0, lob read-ahead reads 0, lob page server read-ahead reads 0. Table 'Workfile'. Scan count 0, logical reads 0, physical reads 0, page server reads 0, read-ahead reads 0, page server read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob page server reads 0, lob read-ahead reads 0, lob page server read-ahead reads 0. Table 'StateProvinces'. Scan count 1, logical reads 2, physical reads 0, page server reads 0, read-ahead reads 0, page server read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob page server reads 0, lob read-ahead reads 0, lob page server read-ahead reads 0. Table 'Cities'. Scan count 1, logical reads 497, physical reads 0, page server reads 0, read-ahead reads 0, page server read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob page server reads 0, lob read-ahead reads 0, lob page server read-ahead reads 0. Total execution time: 00:00:00.027
Sådan slukker du det
Indstilling af STATISTICS IO
til ON
påvirker alle efterfølgende T-SQL-sætninger, indtil den slås fra.
For at slå det fra skal du blot køre det igen ved at bruge OFF
i stedet for ON
:
SET STATISTICS IO OFF;