sqlskills-logo-2015-white.png

MSQL_DQ and PREEMPTIVE_COM_QUERYINTERFACE–Two Sides of the Same Coin

The MSQL_DQ wait type accumulates while waiting for a distributed query to complete and it is not necessarily indicative of an issue.

If MSQL_DQ is one of your top wait types accumulated on your SQL Server instance, you may also see an associated PREEMPTIVE_COM_QUERYINTERFACE wait type.  And actually, you may see that the accumulated values are identical between these two wait types.  PREEMPTIVE_COM_QUERYINTERFACE basically represents accumulated wait time for linked server queries and remote operations as well.

To illustrate, I’ll execute the following query that captures total wait stats before and after and returns the delta (I could use XEvents to do this too – but this is an isolated system and I only have one distributed query being executed at a time). 

I’ll execute a distributed query 50 times and we’ll see what accumulates:

-- “Before” state of waits
SELECT wait_type, waiting_tasks_count
INTO #before_waits
FROM sys.dm_os_wait_stats
WHERE wait_type IN ('PREEMPTIVE_COM_QUERYINTERFACE',
                    'MSQL_DQ');
GO

-- Distributed query executed 50 times
SELECT 'x'
FROM    OPENQUERY ( [JOSEPHSACK-PC\AUGUSTUS] ,'SELECT TOP 1 o1.name
                    FROM master.dbo.sysobjects AS o1' );
GO 50


-- “After” state of waits
SELECT wait_type, waiting_tasks_count
INTO #after_waits
FROM sys.dm_os_wait_stats
WHERE wait_type IN ('PREEMPTIVE_COM_QUERYINTERFACE',
                    'MSQL_DQ');
GO

SELECT    a.wait_type, 
        (a.waiting_tasks_count - b.waiting_tasks_count) AS accumulated_waiting_tasks_count
FROM #before_waits AS b
INNER JOIN #after_waits AS a ON
    b.wait_type = a.wait_type;
GO

DROP TABLE #before_waits;
DROP TABLE #after_waits

This returns the following (after the 50 result sets, of course):

image

Why care? 

Because if MSQL_DQ is 25% of your accumulated wait time for the SQL Server instance – and PREEMPTIVE_COM_QUERYINTERFACE is also a matching 25% of your wait time, this doesn’t truly represent 50% of your overall wait time.  You may overlook wait types with lower accumulated wait times  – and in this scenario that may be a mistake.

Other articles

Imagine feeling confident enough to handle whatever your database throws at you.

With training and consulting from SQLskills, you’ll be able to solve big problems, elevate your team’s capacity, and take control of your data career.