Skip to main content

Analyze Tracking Query Usage

Configurable Joins doesn't currently support the [query.run.id] table.

Find which queries have the most saved rows.

SELECT q.[id]
ย  ย  ,q.[name]
ย  ย  ,format(count(qri.[identity]), '###,###,###') [Saved Rowcount]
ย  ย  ,min(qr.[created]) [First Run]
ย  ย  ,max(qr.[created]) [Last Run]
FROM [query] q
INNER JOIN [query.run] qr
ย  ย  ON qr.[query] = q.[id]
INNER JOIN [query.run.id] qri
ย  ย  ON qri.[run] = qr.[id]
GROUP BY q.[id]
ย  ย  ,q.[name]
ORDER BY count(qri.[identity]) DESC

Find the total number of saved rows in your database (Current) and how close you are to hitting the limit (Lifetime), which is 2,147,483,647 or the largest number SQL Server can stored in anย int column. Slate will crash when you hit that limit. Technolutions can reset it if you've cleared out some existing rows.

SELECT format(count([identity]), '###,###,###') [Current]
	,format(max([identity]), '###,###,###') [Lifetime]
FROM [query.run.id]

Query the table's index is a much faster method to get a rowcount, even though it's theoretically possible for it to be wrong. Slate is pretty good at keeping accurate indexes.

SELECT format([rows], '###,###,###') [rows]
FROM sysindexes
WHERE id = OBJECT_ID('[query.run.id]')
	AND indid < 2