如何獲取有關係統視圖索引的信息。如何獲取有關係統視圖索引的信息
我寫這個查詢,看執行plan.I看到它使用索引掃描,而索引seek.Any一知道爲什麼?
SELECT OBJECT_NAME(OBJECT_ID) TableName, st.row_count
FROM sys.dm_db_partition_stats st
WHERE index_id < 2 AND OBJECT_NAME(OBJECT_ID)='Mytbl'
如何獲取有關係統視圖索引的信息。如何獲取有關係統視圖索引的信息
我寫這個查詢,看執行plan.I看到它使用索引掃描,而索引seek.Any一知道爲什麼?
SELECT OBJECT_NAME(OBJECT_ID) TableName, st.row_count
FROM sys.dm_db_partition_stats st
WHERE index_id < 2 AND OBJECT_NAME(OBJECT_ID)='Mytbl'
select i.name as idx_name,
i.type_desc,
i.is_unique,
ac.name as col_name,
c.key_ordinal,
c.is_descending_key,
c.is_included_column
from sys.indexes i
join sys.all_objects a
on a.object_id = i.object_id
join sys.index_columns c
on c.object_id = i.object_id
and c.index_id = i.index_id
join sys.all_columns ac
on ac.object_id = i.object_id
and c.column_id = ac.column_id
where a.name = 'sysidxstats'
返回
idx_name type_desc is_unique col_name key_ordinal is_descending_key is_included_column
----------------- --------------- --------- ----------- ----------- ----------------- ------------------
clst CLUSTERED 1 id 1 0 0
clst CLUSTERED 1 indid 2 0 0
nc NONCLUSTERED 1 name 1 0 0
nc NONCLUSTERED 1 id 2 0 0
使用
SELECT OBJECT_NAME(object_id) TableName,
st.row_count
FROM sys.dm_db_partition_stats st
WHERE index_id < 2
AND object_id = OBJECT_ID('Mytbl')
爲了得到一個索引查找。
WHERE OBJECT_NAME(object_id)='Mytbl'
不是可搜索謂語。
+1,構建得非常好的答案 – Lamak 2011-03-28 13:02:51
退房這個職位http://blog.sqlauthority.com/2009/08/24/sql-server-index-seek-vs-index-scan-diffefence-and-usage-a-simple-note/它不談論如何從系統的觀點得到索引信息,但它確實解釋爲什麼爲什麼索引掃描可以在索引中使用的原因尋找。
你爲什麼在意?系統視圖是系統視圖。這不像你需要優化它們! – 2011-03-28 09:57:34
是的,我想要我的個人信息。 – Arian 2011-03-28 10:17:25
+1我認爲想用掃描替換掃描是完全合理的。 – 2011-03-28 11:35:41