mirror of
https://github.com/postgres/postgres.git
synced 2025-08-25 20:23:07 +03:00
Add additional regression tests for select_active_windows
During the development of 728202b63
, which was aimed at reducing the
number of sorts required to evaluate multiple window functions with
different WindowClause definitions, the code written sorted the
WindowClauses in reverse tleSortGroupRef order. There appears to be no
discussion in the thread which was opened to discuss the development of
this patch and no comments mentioning the fact that having the
WindowClauses in reverse tleSortGroupRef order makes it more likely that
the final WindowClause to be evaluated will provide presorted input to
the query's DISTINCT or ORDER BY clause. The reason for this is that the
tleSortGroupRef indexes are assigned for the DISTINCT and ORDER BY clauses
before they are for the WindowClauses PARTITION BY and ORDER BY clauses.
Putting the WindowClause with the lowest tleSortGroupRef last means that
it's more likely that no additional sorting is required for the query's
DISTINCT or ORDER BY clause.
All we're doing here is adding some tests and a comment to help ensure
that remains true and that we don't accidentally forget to consider this
again should we ever rewrite that code.
Author: Ankit Kumar Pandey, David Rowley
Discussion: https://postgr.es/m/CAApHDvq=g2=ny59f1bvwRVvupsgPHK-KjLPBsSL25fVuGZ4idQ@mail.gmail.com
This commit is contained in:
@@ -5672,6 +5672,14 @@ select_active_windows(PlannerInfo *root, WindowFuncLists *wflists)
|
||||
* Sort the windows by the required sorting clauses. First, compare the sort
|
||||
* clauses themselves. Second, if one window's clauses are a prefix of another
|
||||
* one's clauses, put the window with more sort clauses first.
|
||||
*
|
||||
* We purposefully sort by the highest tleSortGroupRef first. Since
|
||||
* tleSortGroupRefs are assigned for the query's DISTINCT and ORDER BY first
|
||||
* and because here we sort the lowest tleSortGroupRefs last, if a
|
||||
* WindowClause is sharing a tleSortGroupRef with the query's DISTINCT or
|
||||
* ORDER BY clause, this makes it more likely that the final WindowAgg will
|
||||
* provide presorted input for the query's DISTINCT or ORDER BY clause, thus
|
||||
* reducing the total number of sorts required for the query.
|
||||
*/
|
||||
static int
|
||||
common_prefix_cmp(const void *a, const void *b)
|
||||
|
Reference in New Issue
Block a user