2012-11-13 57 views
2

我使用與CONTAINSTABLE函數的查詢,使用字符串搜索是這樣的:「1-1」或類似的(如「1 + 1」或「AA」) 問題該查詢花費的時間太長,並沒有帶來許多結果。 而不是相同的查詢,但與其他搜索字符串像「a」檢索更多的結果,花費更少的時間來完成。 這是查詢:與「1-1」 CONTAINSTABLE性能搜索

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

你知道什麼可以怎麼回事? 謝謝!

下面是執行計劃

Plan

這裏是表文檔創作劇本:

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 
+0

什麼版本的SQL Server?這個計劃是什麼樣子的?嵌套循環計劃內部是否包含表函數,以便重複計算它? –

+0

另外你的問題是什麼。你在問性能或結果嗎? –

+0

我正在使用SQLserver 2008.是的,問題是關於性能,它怎麼會這麼慢。 由於它不帶來很多結果 謝謝。 –

回答

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並分享結果嗎?這可能有助於解釋長時間運行。

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與 '%引擎%',它返回2500

注意,1返回413578 不是我的全文索引的噪音詞。 認爲它可能與此有關?

難道是更多鈔票做CONTAINSTABLE與表,而不是全部的一部分嗎?

CONATINSTABLE對所有表dbo.Document進行搜索,實際上在查詢之後,我將WHERE應用於正在使CONTAINSTABLE執行不必要的工作的Document的字段。 謝謝!