diff --git a/src/backend/executor/nodeWindowAgg.c b/src/backend/executor/nodeWindowAgg.c index 4f882b877b1..3c9b822708c 100644 --- a/src/backend/executor/nodeWindowAgg.c +++ b/src/backend/executor/nodeWindowAgg.c @@ -4933,7 +4933,17 @@ WinGetSlotInFrame(WindowObject winobj, TupleTableSlot *slot, if (isout) *isout = false; if (set_mark) + { + /* + * If RPR is enabled and seek type is WINDOW_SEEK_TAIL, we set the + * mark position unconditionally to frameheadpos. In this case the + * frame always starts at CURRENT_ROW and never goes back, thus + * setting the mark at the position is safe. + */ + if (winstate->rpPattern != NULL && seektype == WINDOW_SEEK_TAIL) + mark_pos = winstate->frameheadpos; WinSetMarkPosition(winobj, mark_pos); + } return 0; out_of_frame: diff --git a/src/backend/utils/adt/windowfuncs.c b/src/backend/utils/adt/windowfuncs.c index efb60c99052..74ef109f72e 100644 --- a/src/backend/utils/adt/windowfuncs.c +++ b/src/backend/utils/adt/windowfuncs.c @@ -682,7 +682,7 @@ window_last_value(PG_FUNCTION_ARGS) WinCheckAndInitializeNullTreatment(winobj, true, fcinfo); result = WinGetFuncArgInFrame(winobj, 0, - 0, WINDOW_SEEK_TAIL, false, + 0, WINDOW_SEEK_TAIL, true, &isnull, NULL); if (isnull) PG_RETURN_NULL();