码迷,mamicode.com
首页 > 其他好文 > 详细

Fulltext Index Study7: maintain fragment

时间:2016-06-27 15:38:20      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:

A fulltext index uses internal tables called full-text index fragments to store the inverted index data.

一,查看fragment

1, sys.fulltext_index_fragments

Status of the fragment, one of:

  • 0 = Newly created and not yet used
  • 1 = Being used for insert during fulltext index population or merge
  • 4 = Closed. Ready for query
  • 6 = Being used for merge input and ready for query
  • 8 = Marked for deletion. Will not be used for query and merge source.

A status of 4 or 6 means that the fragment is part of the logical full-text index and can be queried; that is, it is a queryable fragment.

2,统计queryable fragments的数量和百分比

The sys.fulltext_index_fragments catalog view can be used to query the number of fragments comprising a full-text index. If you are experiencing slow full-text query performance, you can use sys.fulltext_index_fragments to query for the number of queryable fragments (status = 4 or 6)  in the full-text index, as follows:

select object_name(table_id) as TableName,
    sum(iif(status in(4,6),1,0)) as Queryable_Fragments,
    sum(iif(status in(4,6),1,0))/count(0) as Queryable_Fragment_Percent
from sys.fulltext_index_fragments
group by table_id


3,重新组织Fragments

If many queryable fragments exist, Microsoft recommends that you reorganize the full-text catalog that contains the full-text index to merge the fragments together.

使用alter fulltext catalog 重新组织fragments。

ALTER FULLTEXT CATALOG catalog_name 
{ REBUILD [ WITH ACCENT_SENSITIVITY = { ON | OFF } ]
| REORGANIZE
| AS DEFAULT 
}

REBUILD               

Tells SQL Server to rebuild the entire catalog. When a catalog is rebuilt, the existing catalog is deleted and a new catalog is created in its place. All the tables that have full-text indexing references are associated with the new catalog. Rebuilding resets the full-text metadata in the database system tables. 

REORGANIZE               

Tells SQL Server to perform a master merge, which involves merging the smaller indexes created in the process of indexing into one large index. Merging the full-text index fragments can improve performance and free up disk and memory resources. If there are frequent changes to the full-text catalog, use this command periodically to reorganize the full-text catalog.

REORGANIZE also optimizes internal index and catalog structures.

Keep in mind that, depending on the amount of indexed data, a master merge may take some time to complete. Master merging a large amount of data can create a long running transaction, delaying truncation of the transaction log during checkpoint. In this case, the transaction log might grow significantly under the full recovery model. As a best practice, ensure that your transaction log contains sufficient space for a long-running transaction before reorganizing a large full-text index in a database that uses the full recovery model.

 

--get catalog name
select icu.object_id,icu.index_id as unique_index_ID,
    c.name as catalog_name,
    c.data_space_id,
    c.file_id,
    c.is_default,
    c.is_accent_sensitivity_on
from sys.fulltext_index_catalog_usages icu 
inner join sys.fulltext_catalogs c 
    on icu.fulltext_catalog_id=c.fulltext_catalog_id
where icu.object_id=xxxx

--rebuild catalog
alter fulltext catalog catalog_name
rebuild with ACCENT_SENSITIVITY=ON;
--reorganize catalog 
alter fulltext catalog catalog_name
REORGANIZE;


 

参考doc:

sys.fulltext_index_fragments (Transact-SQL)

ALTER FULLTEXT CATALOG (Transact-SQL)

Fulltext Index Study7: maintain fragment

标签:

原文地址:http://www.cnblogs.com/ljhdo/p/5620178.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!