Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sp_BlitzCache - Incorrect Percent Memory Grant Used Calculations #3313

Closed
mdpenguin opened this issue Jul 26, 2023 · 3 comments · Fixed by #3318
Closed

sp_BlitzCache - Incorrect Percent Memory Grant Used Calculations #3313

mdpenguin opened this issue Jul 26, 2023 · 3 comments · Fixed by #3318

Comments

@mdpenguin
Copy link
Contributor

Version of the script

  • 8.15 - 20230613

What is the current behavior?

  • PercentMemoryGrantUsed is calculated as:
CAST(ISNULL(NULLIF(( max_used_grant_kb * 1.00 ), 0) / NULLIF(min_grant_kb, 0), 0) * 100. AS MONEY) AS PercentMemoryGrantUsed
  • This doesn't calculate the percent of memory grant that was used by the query because the two numbers aren't related. There's also no reason to believe that the maximum/minimum used grant reflects the amount of memory used when the maximum/minimum grant was granted.

If the current behavior is a bug, please provide the steps to reproduce.

  • Run SP

What is the expected behavior?

  • A better calculation would use total_used_grant_kb / total_grant_kb as this will cover all memory usage since SP was compiled

Which versions of SQL Server and which OS are affected by this issue? Did this work in previous versions of our procedures?

  • All versions of SQL Server and All OS's are affected. This appears to have been how the metric has always been calculated.
@mdpenguin mdpenguin changed the title Incorrect Percent Memory Grant Used Calculations sp_BlitzCache - Incorrect Percent Memory Grant Used Calculations Jul 26, 2023
@mdpenguin
Copy link
Contributor Author

@erikdarlingdata, why have you assigned this to me? Are you asking me to make a PR?

@erikdarlingdata
Copy link
Contributor

@mdpenguin yes, I assigned the issue you to you because you opened it and seemed to have a clear idea of what the code change should be. If you don't want it assigned to you I can remove it.

@BrentOzar
Copy link
Member

Thanks for the pull request. Makes sense. Merging into the dev branch, will be in the next release with credit to you in the release notes.

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

Successfully merging a pull request may close this issue.

3 participants