July 1, 2011 at 8:38 am
Hi All,
In what situations the last_user_update, last_user_seek field is NULL in sys.dm_db_index_usage_stats?
July 1, 2011 at 10:17 am
When there have been no updates or seeks on the index of course 🙂
Here is a quick proof that shows how to achieve that state:
IF EXISTS ( SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'dbo.idx')
AND type IN (N'U') )
DROP TABLE dbo.idx ;
GO
CREATE TABLE dbo.idx (a INT) ;
GO
CREATE INDEX idx_a ON dbo.idx (a)
GO
-- create a scan
SELECT *
FROM dbo.idx;
GO
-- no inserts so no last_user_update, no seek so no last_user_seek
SELECT OBJECT_NAME(object_id),
*
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID()
AND OBJECT_ID('dbo.idx') = object_id ;
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
July 1, 2011 at 10:46 am
The DBV is cleared when SQL restarts or when the database is closed.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
July 1, 2011 at 12:29 pm
...checking on something
EDIT:
OK, had to make sure:
Restarting SQL makes the index disappear from the usage stats view altogether. It's not until the index is used again (in some way) that it appears in the results again.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply