Thursday, April 15, 2021

A little something for exploring placement of SQL Server Parallel Workers

CREATE OR ALTER PROCEDURE scheduler_px_worker__report
AS
BEGIN
;WITH tasks AS
	(SELECT ot.scheduler_id, 
		ot.session_id, 
		ot.exec_context_id
	 FROM sys.dm_os_tasks ot
	 JOIN sys.dm_exec_requests er 
	 ON ot.session_id = er.session_id
	 AND ot.exec_context_id > 0)
SELECT t.scheduler_id, os.parent_node_id,
	spid__exec_context_id = STRING_AGG(CONVERT(VARCHAR(4), t.session_id) 
	                        + ':' + CONVERT(VARCHAR(4), t.exec_context_id), ', ') 
		WITHIN GROUP (ORDER BY t.session_id, t.exec_context_id)
FROM tasks t
JOIN sys.dm_os_schedulers os
ON t.scheduler_id = os.scheduler_id
GROUP BY os.parent_node_id, t.scheduler_id
ORDER BY os.parent_node_id, t.scheduler_id;
END


No comments:

Post a Comment