diff options
author | David Rowley <drowley@postgresql.org> | 2023-01-27 16:08:41 +1300 |
---|---|---|
committer | David Rowley <drowley@postgresql.org> | 2023-01-27 16:08:41 +1300 |
commit | 456fa635a909ee36f73ca84d340521bd730f265f (patch) | |
tree | b987b3e29dd74e2382bc0a257d0cee76c5993556 /src/backend/utils/adt/windowfuncs.c | |
parent | 783d8abc3b63267194ca21b679caf8d152b93358 (diff) | |
download | postgresql-456fa635a909ee36f73ca84d340521bd730f265f.tar.gz postgresql-456fa635a909ee36f73ca84d340521bd730f265f.zip |
Teach planner about more monotonic window functions
9d9c02ccd introduced runConditions for window functions to allow
monotonic window function evaluation to be made more efficient when the
window function value went beyond some value that it would never go back
from due to its monotonic nature. That commit added prosupport functions
to inform the planner that row_number(), rank(), dense_rank() and some
forms of count(*) were monotonic. Here we add support for ntile(),
cume_dist() and percent_rank().
Reviewed-by: Melanie Plageman
Discussion: https://postgr.es/m/CAApHDvqR+VqB8s+xR-24bzJbU8xyFrBszJ17qKgECf7cWxLCaA@mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/windowfuncs.c')
-rw-r--r-- | src/backend/utils/adt/windowfuncs.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/backend/utils/adt/windowfuncs.c b/src/backend/utils/adt/windowfuncs.c index af13b8e53d5..b87a624fb2f 100644 --- a/src/backend/utils/adt/windowfuncs.c +++ b/src/backend/utils/adt/windowfuncs.c @@ -288,6 +288,15 @@ window_percent_rank_support(PG_FUNCTION_ARGS) { Node *rawreq = (Node *) PG_GETARG_POINTER(0); + if (IsA(rawreq, SupportRequestWFuncMonotonic)) + { + SupportRequestWFuncMonotonic *req = (SupportRequestWFuncMonotonic *) rawreq; + + /* percent_rank() is monotonically increasing */ + req->monotonic = MONOTONICFUNC_INCREASING; + PG_RETURN_POINTER(req); + } + if (IsA(rawreq, SupportRequestOptimizeWindowClause)) { SupportRequestOptimizeWindowClause *req = (SupportRequestOptimizeWindowClause *) rawreq; @@ -362,6 +371,15 @@ window_cume_dist_support(PG_FUNCTION_ARGS) { Node *rawreq = (Node *) PG_GETARG_POINTER(0); + if (IsA(rawreq, SupportRequestWFuncMonotonic)) + { + SupportRequestWFuncMonotonic *req = (SupportRequestWFuncMonotonic *) rawreq; + + /* cume_dist() is monotonically increasing */ + req->monotonic = MONOTONICFUNC_INCREASING; + PG_RETURN_POINTER(req); + } + if (IsA(rawreq, SupportRequestOptimizeWindowClause)) { SupportRequestOptimizeWindowClause *req = (SupportRequestOptimizeWindowClause *) rawreq; @@ -465,6 +483,18 @@ window_ntile_support(PG_FUNCTION_ARGS) { Node *rawreq = (Node *) PG_GETARG_POINTER(0); + if (IsA(rawreq, SupportRequestWFuncMonotonic)) + { + SupportRequestWFuncMonotonic *req = (SupportRequestWFuncMonotonic *) rawreq; + + /* + * ntile() is monotonically increasing as the number of buckets cannot + * change after the first call + */ + req->monotonic = MONOTONICFUNC_INCREASING; + PG_RETURN_POINTER(req); + } + if (IsA(rawreq, SupportRequestOptimizeWindowClause)) { SupportRequestOptimizeWindowClause *req = (SupportRequestOptimizeWindowClause *) rawreq; |