Skip to content

Commit 5c542ec

Browse files
Merge pull request #637 from erikdarlingdata/revert/file-io-labels
Revert File I/O label change (premature)
2 parents 9c2a77f + fb84cb6 commit 5c542ec

2 files changed

Lines changed: 20 additions & 38 deletions

File tree

Lite/Services/RemoteCollectorService.FileIo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ private static (string DatabaseName, string FileName, string FileType, string Ph
199199
int DatabaseId, int FileId) ReadFileIoRow(SqlDataReader reader)
200200
{
201201
return (
202-
DatabaseName: reader.IsDBNull(0) ? $"DB_{reader.GetValue(13)}" : reader.GetString(0),
203-
FileName: reader.IsDBNull(1) ? $"File_{reader.GetValue(14)}" : reader.GetString(1),
204-
FileType: reader.IsDBNull(2) ? "UNKNOWN" : reader.GetString(2),
202+
DatabaseName: reader.IsDBNull(0) ? "Unknown" : reader.GetString(0),
203+
FileName: reader.IsDBNull(1) ? "Unknown" : reader.GetString(1),
204+
FileType: reader.IsDBNull(2) ? "Unknown" : reader.GetString(2),
205205
PhysicalName: reader.IsDBNull(3) ? "" : reader.GetString(3),
206206
SizeMb: reader.IsDBNull(4) ? 0m : reader.GetDecimal(4),
207207
NumOfReads: reader.IsDBNull(5) ? 0L : reader.GetInt64(5),

install/08_collect_query_stats.sql

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -222,38 +222,6 @@ BEGIN
222222
row_hash binary(32) NULL
223223
);
224224

225-
/*
226-
Pre-build list of ONLINE, accessible database IDs.
227-
This prevents any downstream DMV calls (dm_exec_sql_text,
228-
dm_exec_plan_attributes) from touching RESTORING databases
229-
on passive mirror servers — which triggers severity 22 dumps.
230-
*/
231-
CREATE TABLE
232-
#online_databases
233-
(
234-
database_id integer NOT NULL PRIMARY KEY,
235-
database_name sysname NOT NULL
236-
);
237-
238-
INSERT INTO
239-
#online_databases
240-
(
241-
database_id,
242-
database_name
243-
)
244-
SELECT
245-
d.database_id,
246-
d.name
247-
FROM sys.databases AS d
248-
WHERE d.state = 0
249-
AND HAS_DBACCESS(d.name) = 1
250-
AND d.database_id NOT IN
251-
(
252-
1, 2, 3, 4, 32761, 32767,
253-
DB_ID(N'PerformanceMonitor')
254-
)
255-
AND d.database_id < 32761;
256-
257225
INSERT INTO
258226
#query_stats_staging
259227
(
@@ -306,7 +274,7 @@ BEGIN
306274
)
307275
SELECT
308276
server_start_time = @server_start_time,
309-
database_name = od.database_name,
277+
database_name = d.name,
310278
sql_handle = qs.sql_handle,
311279
statement_start_offset = qs.statement_start_offset,
312280
statement_end_offset = qs.statement_end_offset,
@@ -385,9 +353,23 @@ BEGIN
385353
qs.statement_start_offset,
386354
qs.statement_end_offset
387355
) AS tqp
388-
INNER JOIN #online_databases AS od
389-
ON st.dbid = od.database_id
356+
CROSS APPLY
357+
(
358+
SELECT
359+
dbid = CONVERT(integer, pa.value)
360+
FROM sys.dm_exec_plan_attributes(qs.plan_handle) AS pa
361+
WHERE pa.attribute = N'dbid'
362+
) AS pa
363+
INNER JOIN sys.databases AS d
364+
ON pa.dbid = d.database_id
390365
WHERE qs.last_execution_time >= @cutoff_time
366+
AND d.state = 0 /*ONLINE only — skip RESTORING databases (mirroring/AG secondary)*/
367+
AND pa.dbid NOT IN
368+
(
369+
1, 2, 3, 4, 32761, 32767,
370+
DB_ID(N'PerformanceMonitor')
371+
)
372+
AND pa.dbid < 32761 /*exclude contained AG system databases*/
391373
OPTION(RECOMPILE);
392374

393375
/*

0 commit comments

Comments
 (0)