0

它看起来 FREETEXTTABLE 只允许 searchkey 参数作为变量,如下所示:

FROM FREETEXTTABLE(dbo.SampleTable, SampleColumn, @searchKey)

我有一个列表 searchKey 值,大约 50000 条记录,如何使用 FREETEXTTABLE“加入”searchKey 表

我用过 WHILE 但速度很慢

DECLARE @results as table(
    Key NVARCHAR(100),
    Rank INT
)

declare @numberOfRows INT = SELECT MAX(Id) FROM dbo.SearchKeyTable)
declare @step int = (SELECT MIN(Id) FROM dbo.SearchKeyTable)

WHILE (@step <= @numberOfRows)
BEGIN
    declare @searchKey NVARCHAR(500) = (Select TOP(1) '''' + REPLACE([Description], '''', '"')  + ''' OR ''' + REPLACE([itemname], '''', '"') + '''' From dbo.SearchKeyTable where id = @step ORDER BY Id)

    insert into @results
    select [Key] as KeyId, SUM([Rank]) as TotalRank FROM FREETEXTTABLE(dbo.SampleTable, SampleColumn, @searchKey) GROUP BY [Key]

    SET @step = @step + 1
END

select * from @results

我的 dbo.SampleTable 表也很大,大约 1600 万条记录

4

1 回答 1

0

目前的解决方法:用c#多线程代替WHILE

于 2018-06-19T19:44:37.977 回答