How to join DMVs to get the data for finding queries running on certain CPU id in SQL Server

177 Views Asked by At

From here (script 1) I am using the script shown to find spids for parallel AG threads

select 
    db_name(database_id) as dbname, 
    command, session_id 
from
    sys.dm_exec_requests 
where 
    command in ('PARALLEL REDO HELP TASK', 'PARALLEL REDO TASK', 'DB STARTUP') 
    and database_id = db_id('AdventureWorks2016')

We are trying to troubleshoot redo queue issues so need to find user queries spids if running on same CPU ids

I found below query (script 2) from here which gives cpu id for running queries

SELECT
    s.cpu_id,
    s.status,
    db_name(r.database_id) as [databaseName],
    w.last_wait_type, 
    w.return_code,
    t.task_state,
    t.pending_io_count,
    t.session_id,
    r.sql_handle,
    te.text
FROM  sys.dm_os_Schedulers s 
JOIN sys.dm_os_workers w 
    ON w.scheduler_address = s.scheduler_address
JOIN sys.dm_os_tasks t 
    ON t.task_address = w.task_address
JOIN sys.dm_exec_requests r 
    ON r.scheduler_id = s.scheduler_id
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) te   
order by 1,3

How can i join above 2 queries as single script to tell me if user queries from script 2 are actually running on same cpu id as one for spids in script 1 OR may be group data by cpu id to show queries running on those cpu id. Somehow script 2 shows same query for multiple spids on same cpu id.

Thanks

0

There are 0 best solutions below