If I have some T-SQL code like this:
While @done<1
Begin
WAITFOR DELAY '00:00:30';
Set @done=<some select statement>
End
Is this likely to increase waits for CXPACKET
? Presumably the other processor(s) will be waiting whilst WAITFOR
is running?
Best Answer
When you issue a
WAITFOR
command, the task will start having await_type
ofWAITFOR
. This is a benign wait type and can be ignored.Likewise, when this task enters the suspended state it will get off of the scheduler (processor) so it won't be taking up worker time. We can see this with a simple example:
In another window you can run the following:
My results are as follows:
As for your question of how this will reflect in
sys.dm_os_wait_stats
, upon theWAITFOR
wait type's completion, it will then increment theWAITFOR
type insys.dm_os_wait_stats
for the duration that the task was waiting for:But as said previously, the
WAITFOR
wait type is benign and can generally be ignored.