sql server - Why are these DMVs returning rows for all databases except one? -


i trying query dmvs in sql server 2008 r2.

on server 2 user databases called histrx , openlink. prove have names correct:

select db_id('histrx') -- returns 5 select db_id('openlink') -- returns 7 

if run following query, picking out entries histrx database, 25 rows in result set:

select top 25      total_worker_time/execution_count avg_worker_time,     total_logical_reads/execution_count avg_logical_reads,     db_name(s.dbid) [db_name],     object_name(s.objectid, s.dbid) [object_name],     execution_count,     plan_generation_num,     last_execution_time,     creation_time,     [text],     p.query_plan     sys.dm_exec_query_stats qs     cross apply sys.dm_exec_sql_text(qs.plan_handle) s     cross apply sys.dm_exec_query_plan(qs.plan_handle) p     db_name(s.dbid) = 'histrx' order     avg_logical_reads desc 

if change where clause following, no rows returned:

where     db_name(s.dbid) = 'openlink' 

i know there significant amount of activity on openlink database. if @ recent expensive queries in activity monitor, can see entries openlink, , i'm pretty sure using dmvs underneath.

  • i'm running activity monitor , dmv query under same login
  • that login owner of openlink database
  • if run select * fn_my_permissions (null, 'server'); can see have view server state permissions
  • if remove where clause, see entries other databases such msdb , distribution
  • here screenshot of mappings login. i'm pretty sure shouldn't owner, that's different question.

screenshot of sql server permissions showing db_owner role membership

can tell me why dmv query returning 0 rows database?

quote books online 2008 r2 > sys.dm_exec_sql_text:

dbid smallint id of database. null ad hoc , prepared sql statements.

1) so, type of sql statements, where db_name(s.dbid) = 'openlink' means where null = 'openlink' , predicate evaluated unknown.

2) dbid column not null "non-adhoc , non-prepared sql" statements (ex. stored procedures).

3) sql 2008r2 might dbid "ad hoc , prepared sql statements" sys.dm_exec_plan_attributes ( plan_handle ) function (link) using query:

select      ...     isnull(src.dbid,convert(smallint,att.value)) my_dbid,     db_name(isnull(src.dbid,convert(smallint,att.value))) my_dbname,     ...     sys.dm_exec_query_stats qs     ...     cross apply sys.dm_exec_plan_attributes(qs.plan_handle) att att.attribute='dbid' 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -