Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 大表分页查询的计算列检查性能_Sql_Performance_Tsql_Sql Server 2008_Database Performance - Fatal编程技术网

Sql 大表分页查询的计算列检查性能

Sql 大表分页查询的计算列检查性能,sql,performance,tsql,sql-server-2008,database-performance,Sql,Performance,Tsql,Sql Server 2008,Database Performance,我有这个查询来检索(见下文,为简单起见简称)求职搜索数据。我们正在处理大约一百万张唱片 Select ID from ( Select ID,createDate ,SearchKeyMatchRank ,Row_Number() over(Order By createDate) As rowNumber from Jobs J OUTER APPLY ( Select SearchKeyMatchRank= CA

我有这个查询来检索(见下文,为简单起见简称)求职搜索数据。我们正在处理大约一百万张唱片

Select ID
from
(
    Select ID,createDate
    ,SearchKeyMatchRank
    ,Row_Number() over(Order By createDate) As rowNumber
    from Jobs J
    OUTER APPLY
    (
        Select SearchKeyMatchRank=
        CASE WHEN @searchKey='""' THEN 0
        ELSE
        (Select IsNull([RANK],0) from FREETEXTTABLE(Jobs,title,@searchKey) Where [Key]=J.ID)*4
        +(Select IsNull([RANK],0) from FREETEXTTABLE(Jobs,description,@searchKey) Where [Key]=J.ID)*4
        +(
        select SUM(ISNULL(JS2.[Rank],0))
        from FREETEXTTABLE(JobSkills,skill,@searchKey) JS2
        Where JS2.[Key] in (Select ID from JobSkills Where jobId=J.Id)
        )*2
        END
    ) SMR
    Where
    SearchKeyMatchRank>0 --simplified here
) T2
where
rowNumber>=CASE WHEN @startIndex>0 AND @endIndex>0 THEN @startIndex ELSE rowNumber END
AND rowNumber<=CASE WHEN @startIndex>0 AND @endIndex>0 THEN @endIndex ELSE rowNumber END
如果我起飞 其中SearchKeyMatchRank>0 不到一秒钟

有人知道我们该如何改进吗

有人知道我们该如何改进吗


将列从计算列更改为“常规”列。在您的测试环境中尝试一下,看看性能改进是否相同。

如果列使用非确定性函数,我们采取的方法是在表上定义一个普通列,并添加一个insert/update触发器来更新该值。这样,在更改依赖字段或添加新记录时会有轻微的影响,但不会影响查询性能,因为该列是标准SQL列。它也可以很容易地编入索引。

我们不能将其更改为常规列,因为我们必须根据搜索键动态计算加权排名。如果您有列,您的想法非常棒,您可以应用静态计算。不幸的是,在这种情况下,我们无法做到同样的事情,因为在用户输入之前,我们无法提前知道搜索键。
SearchKeyMatchRank>0