mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
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
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user