2

我正在使用带有 containstable 函数的查询,使用这样的字符串搜索:“1-1”或类似(如“1 1”或“a a”)问题是查询花费的时间太长并且不会带来很多结果. 取而代之的是相同的查询,但使用其他搜索字符串(如“a”)检索更多结果,完成时间要少得多。这是查询:

SELECT     COUNT(d.DocumentID) 
FROM       KnowledgeIndex_Data.dbo.Document d
INNER JOIN CONTAINSTABLE ( KnowledgeIndex_Data.dbo.Document , * , '"1-1"' ) ftt 
        ON ( d.DocumentID = ftt.[Key] )

注意:全文索引的停用词列表不包含 1

你知道会发生什么吗?谢谢!

这是执行计划

计划

这是表格文档的创建脚本:

CREATE TABLE dbo.Document
(
      DocumentID int IDENTITY (1, 1) NOT NULL -- Local int for cross reference tables to save 12 bytes per record
    , DocumentGUID uniqueidentifier NOT NULL

--  , DocumentTypeID tinyint NOT NULL
    , DocumentSourceID smallint NOT NULL -- New Document Source identifier
    , SourceDocumentID nvarchar(80) NOT NULL --crb 2011/08/23 changed from nvarchar(40) to support PageCodes -- asw 2010/02/12 renamed to make purpose more clear

    , DocumentStructureID tinyint NOT NULL -- New Document Structure identifier

    , SortOrder nvarchar(450) NOT NULL -- 2010/06/18 bdw- Add the Sort Order column and index to the Document table

    , ResultDisplayContent xml (DOCUMENT DocumentResultDisplayContentSchemaCollection) NOT NULL  -- Required For All DocumentTypes -- jci 2011/02/22 DOCUMENT added -- jci 2010/07/02 xml schema added
    , DetailDisplayContent xml (DOCUMENT DocumentDetailDisplayContentSchemaCollection) NULL -- Only required for some DocumentTypes -- jci 2011/02/22 DOCUMENT added  -- jci 2011/0/31 xml schema added
    , TeaserDisplayContent xml (DOCUMENT DocumentResultDisplayContentSchemaCollection) NULL -- Teaser Result data. Optional, replaced with main ResultDisplayContent if null. -- jci 2011/02/22 DOCUMENT added -- jci 2010/07/02 xml schema added

, TitleQueryContent nvarchar(max) NOT NULL
, QueryContent nvarchar(max) NOT NULL

, CreatedAt datetimeoffset(2) NOT NULL

, CONSTRAINT pcDocument PRIMARY KEY CLUSTERED -- jci 2011/07/01 replaced -- CONSTRAINT pncDocument PRIMARY KEY NONCLUSTERED
    ( DocumentID ) WITH FILLFACTOR = 100
, CONSTRAINT fkDocumentDocumentSourceID FOREIGN KEY
    ( DocumentSourceID )
    REFERENCES dbo.DocumentSource ( DocumentSourceID )
    ON DELETE CASCADE
, CONSTRAINT fkDocumentDocumentStructureID FOREIGN KEY
    ( DocumentStructureID )
    REFERENCES dbo.DocumentStructure ( DocumentStructureID )
    ON DELETE CASCADE
)
GO

和索引:

-- Create Index On Table
CREATE FULLTEXT INDEX ON dbo.Document(QueryContent LANGUAGE N'English' , TitleQueryContent LANGUAGE N'English')
    KEY INDEX pcDocument -- 2011/07/01 replaced --pncDocument
    ON (FILEGROUP SECONDARY)
    WITH STOPLIST = SrsStopWordList -- Use SrsStopWordList
        , CHANGE_TRACKING = OFF , NO POPULATION; -- Update Manually For Performance

GO
4

2 回答 2

0

我做了如下查询:

   SELECT count(*) FROM sys.dm_fts_index_keywords(db_id('KnowledgeIndex_Data'),              object_id('dbo.Document'))
   where display_term like '%1-1%'
   GO

它返回 685053 和 '%nn1%' ir 返回 413578 和 '%engine%' 它返回 2500

请注意,对于我的全文索引,1 不是干扰词。认为这可能与此有关吗?

用表的一部分而不是全部做一个 CONTAINSTABLE 是可能的吗?

CONTAINSTABLE 对所有表 dbo.Document 进行搜索,实际上在该查询之后,我将 WHERE 应用于 Document 的一个字段,这使得 CONTAINSTABLE 做不必要的工作。谢谢!

于 2012-11-14T18:27:05.597 回答
0

在搜索词上运行 sys.dm_fts_parser 会产生以下结果 -

select  *from sys.dm_fts_parser('"1-1"', 1033, 0 ,0)

display_term    expansion_type  source_term
1                0       1-1
nn1              0       1-1
1                0       1-1
nn1              0       1-1

所以全文引擎最终会搜索 4 个不同的搜索词,然后组合结果。你能用 display_term LIKE '1' 或 'nn1' 在你的桌子上运行 sys.dm_fts_index_keywords 并分享结果吗?这可能有助于解释长期运行时间。

于 2012-11-14T16:35:49.153 回答