From 66c136c8a35d2503f1d16cbc21434589e9326876 Mon Sep 17 00:00:00 2001 From: Henson Choi Date: Fri, 19 Jun 2026 14:17:19 +0900 Subject: [PATCH] Document eval_nav_offset_helper's NULL/negative offset handling eval_nav_offset_helper pre-evaluates a navigation offset at executor init to size the frame trim, returning 0 for a NULL or negative offset rather than rejecting it. The comment did not say why, leaving the purpose of the function and of those branches unclear. Explain that a NULL or negative offset is caught per row on the navigation path that consumes it, which errors out before navigation produces any result, so the trim value computed here is never used. The branches are reachable -- a navigation offset can be a run-time constant such as a Param -- and are already covered by the PREV(price, $1) tests in rpr.sql, so they need neither a new test nor an assertion. --- src/backend/executor/nodeWindowAgg.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/backend/executor/nodeWindowAgg.c b/src/backend/executor/nodeWindowAgg.c index 04e6b31aea1..d047314a191 100644 --- a/src/backend/executor/nodeWindowAgg.c +++ b/src/backend/executor/nodeWindowAgg.c @@ -3984,10 +3984,15 @@ put_notnull_info(WindowObject winobj, int64 pos, int argno, bool isnull) /* * eval_nav_offset_helper - * Evaluate an offset expression at executor init time for trim - * optimization. Returns the offset value, or 0 for NULL/negative - * (these will cause a runtime error during actual navigation, so the - * trim value is irrelevant). + * Pre-evaluate a navigation offset expression at executor init time, to + * bound how far navigation can reach (which sizes the frame trim). + * Returns the offset value, or 0 for a NULL or negative offset. + * + * The offset is not validated here. A NULL or negative value is caught later, + * per row, on the navigation path that consumes it (see EEOP_RPR_NAV_SET in + * execExprInterp.c), which errors out before navigation produces any result; + * the trim sizing computed from such an offset is therefore never used, and 0 + * is returned as a harmless placeholder. */ static int64 eval_nav_offset_helper(WindowAggState *winstate, Expr *offset_expr,