Fulltext Index Study1:Usage

一,在创建Fulltext Index的table上,必须使用Key Index(unique, single-key, non-nullable column)

CREATE UNIQUE INDEX ui_dbLogID
ON [dbo].[DatabaseLog]([DatabaseLogID]);

The KEY INDEX must be a unique, single-key, non-nullable column. Select the smallest unique key index for the full-text unique key. For the best performance, we recommend an integer data type for the full-text key.

二,创建Fulltext Catalog,一个Fulltext Index 必须存在于一个Catalog中

One full-text catalog can have several full-text indexes, but a full-text index can only be part of one full-text catalog. Each database can contain zero or more full-text catalogs. The catalog name must be unique among all catalog names in the current database.

create fulltext catalog catalog_test
as default;

参考doc:CREATE FULLTEXT CATALOG (Transact-SQL)

三,CREATE FULLTEXT INDEX

Only one full-text index is allowed per table or indexed view, and each full-text index applies to a single table or indexed view.

create fulltext index
on [dbo].[DatabaseLog]
(
[TSQL] language 1033
)
key index ui_dbLogID
on (catalog_test,FILEGROUP [primary])    --filegroup
with
( CHANGE_TRACKING=off ,NO POPULATION );

参考doc:CREATE FULLTEXT INDEX (Transact-SQL)

CREATE FULLTEXT INDEX ON table_name
   [ ( { column_name
             [ TYPE COLUMN type_column_name ]
             [ LANGUAGE language_term ]
             [ STATISTICAL_SEMANTICS ]
        } [ ,...n]
      ) ]
    KEY INDEX index_name
    [ ON <catalog_filegroup_option> ]
    [ WITH [ ( ] <with_option> [ ,...n] [ ) ] ]
[;]

<catalog_filegroup_option>::=
 {
    fulltext_catalog_name
 | ( fulltext_catalog_name, FILEGROUP filegroup_name )
 | ( FILEGROUP filegroup_name, fulltext_catalog_name )
 | ( FILEGROUP filegroup_name )
 }

<with_option>::=
 {
   CHANGE_TRACKING [ = ] { MANUAL | AUTO | OFF [, NO POPULATION ] }
 | STOPLIST [ = ] { OFF | SYSTEM | stoplist_name }
 | SEARCH PROPERTY LIST [ = ] property_list_name
 }

1,type column type_column_name

  This column, known as the type column, contains a user-supplied file extension (.doc, .pdf, .xls, and so forth).

  Table中的 一个column,用于存储 file extension(文件扩展名)。

2,language,When creating a full-text index, you need to specify a column-level language for the indexed column.

language_term is optional and can be specified as a string, integer, or hexadecimal value corresponding to the locale identifier (LCID) of a language. If no value is specified, the default language of the SQL Server instance is used.

从sys.fulltext_languages 系统视图中查看language的LCID 和 LanguageName。

参考doc: Choose a Language When Creating a Full-Text Index

How Full-Text Search Uses the Name of the Column-Level Language

When creating a full-text index, you need to specify a valid language name for each column. If a language name is valid but not returned by the sys.fulltext_languages (Transact-SQL) catalog view, full-text search falls back to the closest available language name of the same language family, if any. Otherwise, full-text search falls back to the Neutral word breaker. This fall-back behavior might affect the recall accuracy. Therefore we strongly recommend that you specify a valid and available language name for each column when creating a full-text index.

The LCID is used against all data types eligible for full-text indexing (such as char or nchar). If you have the sort order of a char, varchar, or text type column set to a language setting different from the language identified by the LCID, the LCID is used anyway during full-text indexing and querying of those columns.

2,Populate,更新Fulltext Index 的方式

CHANGE_TRACKING [ = ] { MANUAL | AUTO | OFF [ , NO POPULATION ] }

Specifies whether changes (updates, deletes or inserts) made to table columns that are covered by the full-text index will be propagated by SQL Server to the full-text index. Data changes through WRITETEXT and UPDATETEXT are not reflected in the full-text index, and are not picked up with change tracking.

MANUAL                   

Specifies that the tracked changes must be propagated manually by calling the ALTER FULLTEXT INDEX … START UPDATE POPULATION Transact-SQL statement (manual population). You can use SQL Server Agent to call this Transact-SQL statement periodically.

AUTO                  

Specifies that the tracked changes will be propagated automatically as data is modified in the base table (automatic population). Although changes are propagated automatically, these changes might not be reflected immediately in the full-text index. AUTO is the default.

OFF [ , NO POPULATION]                   

Specifies that SQL Server does not keep a list of changes to the indexed data. When NO POPULATION is not specified, SQL Server populates the index fully after it is created.

The NO POPULATION option can be used only when CHANGE_TRACKING is OFF. When NO POPULATION is specified, SQL Server does not populate an index after it is created. The index is only populated after the user executes the ALTER FULLTEXT INDEX command with the START FULL POPULATION or START INCREMENTAL POPULATION clause.

3,STOPLIST

STOPLIST [ = ] { OFF | SYSTEM | stoplist_name }

Associates a full-text stoplist with the index. The index is not populated with any tokens that are part of the specified stoplist. If STOPLIST is not specified, SQL Server associates the system full-text stoplist with the index.

OFF                  

Specifies that no stoplist be associated with the full-text index.

SYSTEM                   

Specifies that the default full-text system STOPLIST should be used for this full-text index.

stoplist_name                                       

Specifies the name of the stoplist to be associated with the full-text index.

4,SEARCH PROPERTY LIST

SEARCH PROPERTY LIST [ = ] property_list_name

Associates a search property list with the index.

OFF                  

Specifies that no property list be associated with the full-text index.

property_list_name                                       

Specifies the name of the search property list to associate with the full-text index.

四,修改Fulltext Index,增加一个column

alter fulltext index
on [dbo].[DatabaseLog]
add ([XmlEvent] language 1033)
WITH NO POPULATION;

参考doc:ALTER FULLTEXT INDEX (Transact-SQL)

ALTER FULLTEXT INDEX ON table_name
   { ENABLE
   | DISABLE
   | SET CHANGE_TRACKING [ = ] { MANUAL | AUTO | OFF }
   | ADD ( column_name
     [ TYPE COLUMN type_column_name ]
     [ LANGUAGE language_term ]
     [ STATISTICAL_SEMANTICS ]
 [,...n] )
     [ WITH NO POPULATION ]
   | ALTER COLUMN column_name
     { ADD | DROP } STATISTICAL_SEMANTICS
     [ WITH NO POPULATION ]
   | DROP ( column_name [,...n] )
     [ WITH NO POPULATION ]
   | START { FULL | INCREMENTAL | UPDATE } POPULATION
   | {STOP | PAUSE | RESUME } POPULATION
   | SET STOPLIST [ = ] { OFF| SYSTEM | stoplist_name }
     [ WITH NO POPULATION ]
   | SET SEARCH PROPERTY LIST [ = ] { OFF | property_list_name }
     [ WITH NO POPULATION ]
   }
[;]

五,Populate Fulltext Index

ALTER FULLTEXT INDEX
ON [dbo].[DatabaseLog]
   START FULL POPULATION;

六,使用 contains 查询 Fulltext Index

如果想要在查询中使用Fulltext Index,必须使用关键字:CONTAINS、FULLTEXT、CONTAINSTABLE、FREETEXTTABLE 告知 SQL Server Engine。

DECLARE @SearchWord nvarchar(30)
SET @SearchWord = N‘Error‘
SELECT [TSQL]
FROM [dbo].[DatabaseLog]
WHERE CONTAINS([TSQL], @SearchWord);

参考doc:CONTAINS (Transact-SQL)

CONTAINS (
     {
        column_name | ( column_list )
      | *
      | PROPERTY ( { column_name }, ‘property_name‘ )
     }
     , ‘<contains_search_condition>‘
     [ , LANGUAGE language_term ]
   ) 

使用Language language_term 制定一个language.

Specifying a Non-default Column-Level Language in a Full-Text Query

By default, in , full-text search will parse the query terms using the language specified for each column that is included in the full-text clause. To override this behavior, specify a nondefault language at query time. For supported languages whose resources are installed, the LANGUAGE language_term clause of a CONTAINS, CONTAINSTABLE, FREETEXT, or FREETEXTTABLE query can be used to specify the language used for word breaking, stemming, thesaurus, and stopword processing of the query terms.

七,Drop Fulltext Index

DROP FULLTEXT INDEX
ON [dbo].[DatabaseLog]
时间: 2024-12-18 01:36:56

Fulltext Index Study1:Usage的相关文章

Fulltext Index Study8:Resouce Consumption

一,查看Disk Consumption 1,通过SSMS查看Full-Text Index 的 Disk Consumption 在Storage->Full Text Catalogs,选择某一个Catalog,点击属性,查看Catalog Size,就是位于Catalog中的属于fulltext的internal tables的总大小. 2,Population Schedule 通过Population Schedule tab,创建schedule和Job,按照schedule对ful

Fulltext Index Study4:management and performance

Only one full-text index is allowed per table. For a full-text index to be created on a table, the table must have a single, unique nonnull column. You can build a full-text index on columns of type char, varchar, nchar, nvarchar, text, ntext, image,

Fulltext Index Study3:Query

在query 语句中,可以使用 contains predicate来调用Fulltext Index,实现比like速度更快的查询.使用contains能够进行term的extract匹配查询或term的前缀匹配查询,还能够进行基于词根的steming查询,基于自定义同义词文件的synonym查询,基于距离和顺序的相邻term查询.和like 相比,contains不能进行后缀匹配查询.如果Fulltext Index 能够满足业务需求,那么Fulltext Index是一个非常不错的选择,跟

Fulltext Index Study2:Pupulate

Creating and maintaining a full-text index involves populating the index by using a process called a population (also known as a crawl). 由于创建Fulltext Index 会消耗大量的系统资源,因此Fulltext Index 必须在系统空间的时间进行maintain和crawl.在创建Fulltext Index时,通过指定 CHANGE_TRACKING

Fulltext Index Study6:Population monitor

一, filter daemon host sys.dm_fts_fdhosts Returns information on the current activity of the filter daemon host or hosts on the server instance. fdhost_process_id:Windows process ID of the filter daemon host. max_thread:Maximum number of threads in th

FULLTEXT INDEX全文索引

给现有的wxinfo表的sourceUrl 字段创建全文索引 ALTER TABLE wxinfoADD FULLTEXT INDEX sourceUrl (sourceUrl) 创建全文索引前: SELECT * FROM wxinfo WHERE sourceUrl LIKE '%查询字符串%' 创建全文索引后: SELECT * FROM wxinfo WHERE MATCH(sourceUrl) AGAINST('查询字符串') 备注1:目前,使用MySQL自带的全文索引时,如果查询字符

Fulltext Index Study7: maintain fragment

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

在MYSQL中运用全文索引(FULLTEXT index)

在MYSQL中使用全文索引(FULLTEXT index) MYSQL的一个很有用的特性是使用全文索引(FULLTEXT index)查找文本的能力.目前只有使用MyISAM类型表的时候有效(MyISAM是默认的表类型,如果你不知道使用的是什么类型的表,那很可能就是 MyISAM).全文索引可以建立在TEXT,CHAR或者VARCHAR类型的字段,或者字段组合上.我们将建立一个简单的表用来解释各种特性.简单用法(MATCH()函数)对3.23.23以后的版本有效,复杂的用法(IN BOOLEAN

无语的index hint:手工分配哈希区,5小时不出结果,优化后20分钟

同事发来一个语句,说5个小时不出结果,我滴个神呀,想看看到底是什么垃圾语句造成的.于是叫同事发过来.不看不知道,一看吓一跳,3个表关联,强制使用了2个index hint,其中一个表9g,一个表67g,还有一个小表40Mb.无知的开发人员,以为走index就是快的,哎... 下面是同事发来的语句: select /*+ parallel(t,4) index(a,IDX_COMMBASUBSHIST_1) index(b,IDX_COMMCMSERVHIST_1)*/ 1, t.DISC_ID,