Skip to content

Conversation

@AaronBertrand
Copy link
Contributor

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.

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.
Copy link

@AMtwo-olo AMtwo-olo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants