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

发布于 2024-12-02 16:49:05 字数 1279 浏览 6 评论 0原文

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

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

注意:

我无法使用常规联接,因为我需要通过将 jobId 传递给 REETEXTTABLE 来查找加权排名。

问题:

速度非常慢。

显然问题是比较计算列。

SearchKeyMatchRank>0

如果我起飞 其中SearchKeyMatchRank>0 只需不到一秒钟。

有人知道我们如何改进这个吗?

I have this query to retrieve (see below, made short for simplicity) search data for jobs. We are dealing with about a million records.

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

NOTES:

I cannot use a regular join since I would need to find weighted ranks by passing the jobId to REETEXTTABLE.

PROBLEM:

Its extremely slow.

Apparently the problem is comparing a computed column.

SearchKeyMatchRank>0

If I take off
Where SearchKeyMatchRank>0
it takes less then a second.

Anybody got an idea how we could improve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尴尬癌患者 2024-12-09 16:49:05

有人知道我们如何改进这个吗?

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

Anybody got an idea how we could improve this?

Change the column from a computed column to a "regular" column. Try it in your test environment and see if the performance improvement is the same.

臻嫒无言 2024-12-09 16:49:05

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

If the column uses a non-deterministic function, the approach we've taken is to define a normal column on the table and add an insert/update trigger to updated the value. In this way, there will be a slight hit when a dependent field is changed or a new record is added, but it will not impact on query performance as the column is a standard SQL column. It can also be indexed easily.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文