简体   繁体   中英

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

I am looking for at what point do windowed functions happen in 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

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. 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.
  • The effect is not related to the ORDER BY (even if you use order by (select null)) ).
  • TOP does not affect the processing.
  • The processing occurs before SELECT DISTINCT .

I think the conclusion is that they are parsed in the SELECT or ORDER BY as with other expressions in those clauses. There is no separate place for them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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