The other day I ran into a very odd issue that when I execute this query:
select * from sys.dm_exec_cached_plans cp inner join sys.dm_exec_procedure_stats ps on ps.plan_handle = cp.plan_handle
It would execute for a long time (10 minutes before I gave up which is much longer than I expected). At the time I ran it I had recently cleared the procedure cache so there were likely no more than 20-30 cached plans.
When I cancel the query it continues to run and never cancels.
I then tried to use the KILL command on the spid. When I look at the query in sys.dm_exec_requests the last wait type was SOS_SCHEDULER_YEILD and the command is KILL/ROLLBACK. Once again I waited for a long time (10 minutes or so)
In order to kill the query I tried to stop the SQL Server service through SQL Configuration Manager. This hung. The only way I could find to stop the query or the service was by using sysinterals tool pskill. Not ideal but it a test installation so no big deal.
I tried to search to see if anyone else has seen this but can't find a search criteria that filters out the noise.
Ive seen this on two boxes in my environment, one SQL Server 2008 R2 SP1 and another SQL Server 2008.
I executed this again just now and it returned quickly (milliseconds).
Can anyone shed any light about this? Am I missing something obvious or is this a bug.
[Edit: adding based on an answer from luvizuvi] I could find no obvious blocking processes or other bottlenecks related to memory, disk, cpu, other processes, etc. When looking at sys.dm_exec_requests this was the only command in a running state.