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_BlitzWho - shows procedure definition not the current statement in query_text if proc is executing for the first time #3163

Closed
Adedba opened this issue Oct 29, 2022 · 5 comments
Assignees

Comments

@Adedba
Copy link
Contributor

Adedba commented Oct 29, 2022

Version of the script
SELECT @Version = '8.11', @VersionDate = '20221013';

What is the current behavior?
If you have a stored procedure executing for the first time (not in the plan cache) the query_text column will not show you the current statement being executed, it will show you the stored procedure definition instead.

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

Clear your cache (DBCC FREEPROCCACHE)

create a stored procedure:

USE [StackOverflow];
GO

CREATE PROCEDURE usp_GetTopVotesByYearAndMonth
AS 
BEGIN 
	
	SELECT /* Query 1 of 2 */ TOP (10) 
		DATENAME(YEAR,[CreationDate]) AS VoteYear,
		COUNT(CreationDate) AS TotalVotes
	FROM [dbo].[Votes] v
	INNER JOIN [dbo].[VoteTypes] vt ON v.[VoteTypeId] = vt.[Id]
	GROUP BY 
		DATENAME(YEAR,[CreationDate])
	ORDER BY 
		[TotalVotes] DESC;	
	
	SELECT /* Query 2 of 2 */ TOP (10) 
		DATENAME(MONTH,[CreationDate]) AS VoteMonth,
		COUNT(CreationDate) AS TotalVotes
	FROM [dbo].[Votes] v
	INNER JOIN [dbo].[VoteTypes] vt ON v.[VoteTypeId] = vt.[Id]
	GROUP BY 
		DATENAME(MONTH,[CreationDate])
	ORDER BY 
		[TotalVotes] DESC;		
END 
go

Query window 1: Execute stored procedure:
EXEC usp_GetTopVotesByYearAndMonth;

Query window 2: Execute sp_BlitzWho:
EXEC sp_BlitzWho
Observer the query_text column, this will contain the stored procedure definition.

Now execute your stored procedure again and the execute sp_BlitzWho whilst running and you will notice that this time the statement being executed will now show in the query_text column.

What is the expected behavior?
For the current statement in a stored procedure to show in the query_text column

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

@Adedba Adedba self-assigned this Oct 29, 2022
Adedba added a commit to Adedba/SQL-Server-First-Responder-Kit that referenced this issue Oct 29, 2022
…ment

BrentOzarULTD#3163 - sp_BlitzWho - shows procedure definition not the current statement.

Ameneded query_text column to get statement offsets from sys.dm_exec_requests instead of sys.dm_exec_query_stats
@Adedba Adedba changed the title sp_BlitzWho - shows procedure definition not the current statement in query_text if proc is executing has just been cached sp_BlitzWho - shows procedure definition not the current statement in query_text if proc is executing for the first time Nov 11, 2022
@BrentOzar
Copy link
Member

Howdy sir! Did you want to code a change for this? If not, let me know and I'll close it - the current implementation is alright for my purposes.

@Adedba
Copy link
Contributor Author

Adedba commented Dec 13, 2022

Hi Brent, yep I have a changed lined up for this one just forgot to create a pull request. Doh! Incoming...

@BrentOzar
Copy link
Member

@Adedba I haven't heard back from you, so I'll go ahead and close this for now, but if you decide you want to work on it, you can leave a comment here when you're ready to do a pull request, and I can reopen it.

Adedba added a commit to Adedba/SQL-Server-First-Responder-Kit that referenced this issue Jan 6, 2023
…requests instead of sys.dm_exec_query_stats

BrentOzarULTD#3163 - Ameneded query_text column to get statement offsets from sys.dm_exec_requests instead of sys.dm_exec_query_stats
@Adedba
Copy link
Contributor Author

Adedba commented Jan 6, 2023

Thanks Brent, I did a commit which was ready to go just forgot to raise a pull request but I have created one now.

@BrentOzar BrentOzar added this to the 2023-01 Release milestone Jan 31, 2023
@BrentOzar
Copy link
Member

Thanks for the pull request! Looks good, 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

No branches or pull requests

3 participants