7.2.5. Window Function Processing

7.2.5. Window Function Processing
7.2.5.窗口函数处理
If the query contains any window functions (see Section 3.5, Section 9.21 and Section 4.2.8), these  functions are evaluated after any grouping, aggregation, and HAVING filtering is performed. That is, if  the query uses any aggregates, GROUP BY , or HAVING , then the rows seen by the window functions  are the group rows instead of the original table rows from FROM / WHERE .
如果查询中包含窗口函数(参见 3.5节9.21节4.2.8节),那么这些函数会在分组、聚合和HAVING之后执行。也就是说,如果查询中包含了聚合、GROUP BY或者HAVING,那么窗口函数所作用的行即为分组之后的行,而不是来自FROM/WHERE的原始行。
 
When multiple window functions are used, all the window functions having syntactically equivalent  PARTITION BY and ORDER BY clauses in their window definitions are guaranteed to be evaluated  in a single pass over the data. Therefore they will see the same sort ordering, even if the ORDER BY  does not uniquely determine an ordering. However, no guarantees are made about the evaluation of  functions having different PARTITION BY or ORDER BY specifications. (In such cases a sort step is  typically required between the passes of window function evaluations, and the sort is not guaranteed  to preserve ordering of rows that its ORDER BY sees as equivalent.)
当使用多个窗口函数  时,所有的窗口函数在其窗口定义中具有等效的PARTITION BY 和ORDER BY子句,确保了其可通过在数据的一次传递来进行评估。 因此,即使ORDER BY不能唯一地确定顺序,它们也将看到相同的排序顺序。但是,不能保证具有不同PARTITION BY或ORDER BY规范的函数也具有相同行为。(在这种情况下,通常在传递窗口函数评估之间需要一个排序步骤,并且不能保证该排序能保留与ORDER BY等效的行的顺序。)
 
Currently, window functions always require presorted data, and so the query output will be ordered  according to one or another of the window functions' PARTITION BY / ORDER BY clauses. It is not  recommended to rely on this, however. Use an explicit top-level ORDER BY clause if you want to be  sure the results are sorted in a particular way.
当前,窗口函数始终需要预排序的数据,因此查询输出将根据窗口函数的PARTITION BY / ORDER BY子句中的一个进行排序。但是,不建议依赖于此。 如果想要确保结果以特定方式排序,请使用显式的ORDER BY子句。
发布了341 篇原创文章 · 获赞 54 · 访问量 88万+

猜你喜欢

转载自blog.csdn.net/ghostliming/article/details/104549673