diff options
Diffstat (limited to 'src/backend/utils')
-rw-r--r-- | src/backend/utils/adt/int8.c | 15 | ||||
-rw-r--r-- | src/backend/utils/adt/windowfuncs.c | 29 |
2 files changed, 38 insertions, 6 deletions
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c index 123b4eb6bfb..41fbeec8fd7 100644 --- a/src/backend/utils/adt/int8.c +++ b/src/backend/utils/adt/int8.c @@ -833,6 +833,21 @@ int8inc_support(PG_FUNCTION_ARGS) SupportRequestWFuncMonotonic *req = (SupportRequestWFuncMonotonic *) rawreq; MonotonicFunction monotonic = MONOTONICFUNC_NONE; int frameOptions = req->window_clause->frameOptions; + WindowFunc *wfunc = req->window_func; + + if (list_length(wfunc->args) == 1) + { + Node *expr = eval_const_expressions(NULL, linitial(wfunc->args)); + + /* + * Due to the Node representation of WindowClause runConditions in + * version prior to v17, we need to insist that the count arg is + * Const to allow safe application of the runCondition + * optimization. + */ + if (!IsA(expr, Const)) + PG_RETURN_POINTER(NULL); + } /* No ORDER BY clause then all rows are peers */ if (req->window_clause->orderClause == NIL) diff --git a/src/backend/utils/adt/windowfuncs.c b/src/backend/utils/adt/windowfuncs.c index b87a624fb2f..0c7cc55845a 100644 --- a/src/backend/utils/adt/windowfuncs.c +++ b/src/backend/utils/adt/windowfuncs.c @@ -14,6 +14,7 @@ #include "postgres.h" #include "nodes/supportnodes.h" +#include "optimizer/optimizer.h" #include "utils/builtins.h" #include "windowapi.h" @@ -486,13 +487,29 @@ window_ntile_support(PG_FUNCTION_ARGS) if (IsA(rawreq, SupportRequestWFuncMonotonic)) { SupportRequestWFuncMonotonic *req = (SupportRequestWFuncMonotonic *) rawreq; + WindowFunc *wfunc = req->window_func; - /* - * ntile() is monotonically increasing as the number of buckets cannot - * change after the first call - */ - req->monotonic = MONOTONICFUNC_INCREASING; - PG_RETURN_POINTER(req); + if (list_length(wfunc->args) == 1) + { + Node *expr = eval_const_expressions(NULL, linitial(wfunc->args)); + + /* + * Due to the Node representation of WindowClause runConditions in + * version prior to v17, we need to insist that ntile arg is Const + * to allow safe application of the runCondition optimization. + */ + if (IsA(expr, Const)) + { + /* + * ntile() is monotonically increasing as the number of + * buckets cannot change after the first call + */ + req->monotonic = MONOTONICFUNC_INCREASING; + PG_RETURN_POINTER(req); + } + } + + PG_RETURN_POINTER(NULL); } if (IsA(rawreq, SupportRequestOptimizeWindowClause)) |