简体   繁体   English

窗口函数在sql的操作顺序中位于何处?

[英]Where do windowed functions lay in sql's order of operations?

I am looking for at what point do windowed functions happen in sql. 我正在寻找窗口函数在sql中发生的时间。 I know they can be used in the SELECT and ORDER BY clauses, so I am inclined to think they happen after ORDER BY , but before TOP 我知道它们可以在SELECTORDER BY子句中使用,所以我倾向于认为它们发生在ORDER BY ,但在TOP之前

Window functions happen when the optimizer decides that they should happen. 当优化程序决定应该发生窗口功能时,就会发生窗口功能。 This is best understood looking at the query plan. 最好看一下查询计划。

SQL Server advertises the logical processing of queries. SQL Server公布查询的逻辑处理 This is used to explaining scoping rules (in particular). 这用于解释作用域规则(尤其是)。 It is not related to how the query is actually executed. 它与查询的实际执行方式无关。

Clearly, the rules for window functions are: 显然,窗口函数的规则是:

  • The effect is after the FROM , WHERE , GROUP BY , and HAVING clauses are processed. 效果是处理FROMWHEREGROUP BYHAVING子句之后。
  • The effect is not related to the ORDER BY (even if you use order by (select null)) ). 效果与ORDER BY无关(即使您使用order by (select null)) )也是如此。
  • TOP does not affect the processing. TOP不会影响处理。
  • The processing occurs before SELECT DISTINCT . 该处理在SELECT DISTINCT之前进行。

I think the conclusion is that they are parsed in the SELECT or ORDER BY as with other expressions in those clauses. 我认为结论是,它们与这些子句中的其他表达式一样,在SELECTORDER BY中进行了解析。 There is no separate place for them. 他们没有单独的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM