インデックスの種類

フィルタ選択されたインデックス

断片化

断片化調査

--インデックスと断片化率の一覧を取得する
SELECT 'ALTER INDEX ' + '[' + C.name + ']' + ' ON [' + D.name + '].[' + B.name + '] REBUILD' AS 'rebuild command'
      ,D.name AS schemaname
      ,B.name AS table_name
      ,C.name AS index_name
      ,A.avg_fragmentation_in_percent
      ,A.page_count

FROM sys.dm_db_index_physical_stats (DB_ID(),null,null,null,null) AS A 

LEFT OUTER JOIN  sys.objects AS B 
ON  A.object_id = B.object_id 

LEFT OUTER JOIN  sys.indexes AS C 
ON  A.object_id = C.object_id  AND A.index_id = C.index_id 

LEFT OUTER JOIN  sys.schemas AS D 
ON  B.schema_id = D.schema_id 

WHERE B.type = 'U'
AND   C.index_id > 0 

--断片化率が30%以上のものを抽出する
AND   A.avg_fragmentation_in_percent > 30 

ORDER BY A.avg_fragmentation_in_percent DESC; 

断片化への対処

再構築と再構成

再構築

alter index [インデックス名] on [テーブル名] rebuild

再構成

alter index [インデックス名] on [テーブル名] reorganize

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS