Open
Conversation
The important changes here are for performance, but there are other benefits as well. Looping/cursor to execute DBCC per database is expensive, as are two #temp tables used to hold/pass results. This is pronounced on servers with a large number of databases. The sysadmin requirement of the DBCC call is prohibitive (and as shown in issue 306 means those without sysadmin get 0s). Since 2016 SP2, we've been able to extract VLF information from a single function call instead of looping over DBCC checks. The function only requires VIEW SERVER STATE, which is more likely to be granted in a lot of environments. This commit checks for those lower permissions and, if we are 2016 SP2+, performs a single call that eliminates the cursor, both temp tables, and the sysadmin requirement. If the object check fails (< 2016 SP2), OR the permissions check fails, then they fall through to the existing cursor/#temp table solution. That still may be an issue if permissions are inadequate, but it doesn't deviate from the current behavior (VLFs full of 0s). I also changed the cursor to a cursor variable, which can have better default performance and also doesn't need close/deallocate.
AMtwo-olo
approved these changes
Oct 2, 2025
AMtwo-olo
left a comment
There was a problem hiding this comment.
Looks good to me.
✅ Better performance
✅ Correct functionality
✅ gracefully degrades to current functionality
Considering anything older than 2016 SP3 has been out of support for over a year, I think bumping to use the newer features makes sense.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The important changes here are for performance, but there are other benefits as well.
Looping/cursor to execute DBCC per database is expensive, as are two #temp tables used to hold/pass results. This is pronounced on servers with a large number of databases.
The sysadmin requirement of the DBCC call is prohibitive (and as shown in issue 306 means those without sysadmin get 0s).
Since 2016 SP2, we've been able to extract VLF information from a single function call instead of looping over DBCC checks. The function only requires VIEW SERVER STATE, which is more likely to be granted in a lot of environments.
This commit checks for those lower permissions and, if we are 2016 SP2+, performs a single call that eliminates the cursor, both temp tables, and the sysadmin requirement.
If the object check fails (< 2016 SP2), OR the permissions check fails, then they fall through to the existing cursor/#temp table solution. That still may be an issue if permissions are inadequate, but it doesn't deviate from the current behavior (VLFs full of 0s).
I also changed the cursor to a cursor variable, which can have better default performance and also doesn't need close/deallocate.