February 1, 2018 at 12:07 am
Comments posted to this topic are about the item Adaptive Query Processing – Batch Mode Memory Grant Feedback
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
February 1, 2018 at 1:04 am
What happens, if you call the procedure again with an ID which has only one entry (so that the granted memory is now much to high)? Will it lower the memory to grant again (which could lead to a ping-pong effect, if you call it several times with different IDs) or was the query plan marked as plan with increased memory?
And what happens, if I call it again with a really big ID (which would lead to another spill to tempdb), would it increase the granted memory a second (and maybe later a third time)?
God is real, unless declared integer.
February 1, 2018 at 7:54 am
t.franz - Thursday, February 1, 2018 1:04 AMWhat happens, if you call the procedure again with an ID which has only one entry (so that the granted memory is now much to high)? Will it lower the memory to grant again (which could lead to a ping-pong effect, if you call it several times with different IDs) or was the query plan marked as plan with increased memory?And what happens, if I call it again with a really big ID (which would lead to another spill to tempdb), would it increase the granted memory a second (and maybe later a third time)?
If the memory grant in the cached plan is 2x > the memory required, then yes, it will lower it. Any spill to disk will bump it up, so it could go up in increasing amounts. Therefore, it is possible that you could have a ping-pong effect - up to a point. If the plan has an unstable memory requirement because of the variance of parameters used, then the memory grant feedback will disable itself for that plan. You can see this with the memory_grant_feedback_loop_disabled XEvent.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
February 1, 2018 at 10:05 am
Hi WayneS,
1. What kind of variances, and how many, before the SQL Server engine disables memory grant feedback on a procedure?
2. It appears that during the initial execution in your example, the memory grant feedback was displayed.. and then subsequent executions use the feedback. Are there any recommendations to follow to have this memory grant feedback initiated so that the users do not have to endure the less than adequate plan/memory optimization for the initial execution?
Thank you
February 1, 2018 at 11:15 am
Jon Patterson - Thursday, February 1, 2018 10:05 AMHi WayneS,1. What kind of variances, and how many, before the SQL Server engine disables memory grant feedback on a procedure?
2. It appears that during the initial execution in your example, the memory grant feedback was displayed.. and then subsequent executions use the feedback. Are there any recommendations to follow to have this memory grant feedback initiated so that the users do not have to endure the less than adequate plan/memory optimization for the initial execution?Thank you
Hi Jon,
1. All that BOL states is "The plan is disabled after several repeated runs of the query". I'll see if I can find out any further information about this and will report back.
2. Check out Trace Flag 9389 at https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql - it looks like that will do it if memory is available.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
March 29, 2018 at 4:03 am
From what I remember sql will do around 30 (32 to be exact?) rounds before disabling feedback.
There is one pretty important thing - if your query will timeout because of reduced memory grant, SQLServer won't emit new grant and you will be stuck.
March 29, 2018 at 7:54 am
[/quote]
I had asked the SQL team at Microsoft about this. They won't release the number, saying it's internal and subject to change as they see how it is being used.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
March 29, 2018 at 8:15 am
This makes sense, considering how 'fresh' this feature is. I will try to verify the number, it was fairly easy to do.
For me the bigger issue was that grants are updated only after successful execution, and on Azure TF9389 is not available as Db setting (you have to contact support to enable it for whole subscription)
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply