我的表中有大約7M記錄,其結構類似如下:奇怪的全文搜索性能問題
create table Locations (LocationID (PK, int, not null),LocationName varchar(100) NOT NULL /*e.g. 'Paris'*/, ItemsNo (int, null), ICode char(1) null /*e.g. 'C'*/, LocationExtended nvarchar(max) null)
HTML版本在這裏: 「創建表的位置(LocationID( PK,INT,不爲空),LOCATIONNAME VARCHAR(100)NOT NULL,ItemsNo(INT,空),ICODE CHAR(1)空,LocationExtended爲nvarchar(最大)空)」
我的查詢是非常簡單的:
select top 20 LocationName, ItemsNo from Locations where contains(LocationExtended,@SearchTerms) and Icode='C' and ItemsNo is not null order by ItemsNO desc
HTML版本在這裏:「從位置選擇前20 LOCATIONNAME,ItemsNo其中包含(LocationExtended,@ SearchTerms)和ICODE = 'C' 和ItemsNo不爲空,以便通過ItemsNO遞減」
當然有是LocationExtended字段的全文目錄。
現在讓我們用一下參數@SearchTerms與索引:
如果我只對LocationID專欄中,我得到了@ SearchTerms =「巴黎和法國」 FAST執行時間聚集索引(因爲LocationExtended字段中包含很少的包含Paris和France關鍵字的記錄),以及@ SearchTerms ='France'的SLOW執行時間(因爲在LocationExtended字段中有數千條記錄,適用於法國的每個城市/城鎮)。
換句話說,結果是這樣的:對@ SearchTerms ='巴黎和法國的回報 :「巴黎」和「巴黎北」和「南巴黎」 爲@ SearchTerms =「法國」返回「巴黎」 ,「Nice」,「Marseille」....等等。
因爲我需要兩種場景來快速運行,所以我在Locations表上創建了一個非聚集索引,包含Icode和ItemsNO列以及包含LocationID的列。
通過使我得到的結果,此新的指數逆轉:超快速的執行時間@ SearchTerms =「法國」,但對於@ SearchTerms =慢時報「巴黎和法國
現在我停留在這一點上。
我提到我的Windows 2003 Server
任何IDEEA,將不勝感激上運行SQL Server 2008。 非常感謝。
我試過(重新編譯)的選項,但沒有任何改進;用CONTAINS表格我有大約10%的改善,但仍然不令人滿意。 – George 2011-03-06 17:39:55