【问题标题】:"and not " vs "or" t sql full text search"and not" vs "or" t sql全文搜索
【发布时间】:2015-07-09 02:59:22
【问题描述】:

我遇到了查询性能问题。我的 where 子句包含,

where .....(type = c) and not (( type = a ) or contains ( ftstype, N'b' ))

如果没有“and not”部分,查询似乎更快。

我想检查“and”是否比“or”更便宜,以便我可以使用以下(根据 demorgans 规则,[c and (a or b)' = c and (a' and b ')])

where .....(type = c) and ( not ( type = a ) and not contains ( ftstype, N'b' ))

我还想检查查询优化器是否考虑了这种转换,以及确定更好的执行计划。 (我不了解 SQL 服务器估算计划。)

【问题讨论】:

  • 你应该为你的请求的每个版本提供 sql server 估计计划。

标签: sql sql-server full-text-search query-performance sqlperformance


【解决方案1】:

如果我没记错的话(我自己有点初学者),“或”选项的成本会更低。使用“或”选项,如果类型不是“a”,甚至在到达代码的“不包含(ftstype N'b'))”部分之前,您将短路处理完整的查询。

这样的事情怎么办……

WHERE ..... (type = c) AND (( type != 'a' ) OR ( ftstype != N'b'))

让我知道你的发现,因为我还在学习。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-02
    • 2012-10-15
    • 1970-01-01
    相关资源
    最近更新 更多