From 81a9b83b9d61704e85d97bc79b10ac6a00d73def Mon Sep 17 00:00:00 2001 From: Henson Choi Date: Wed, 4 Mar 2026 15:53:33 +0900 Subject: [PATCH 5/8] Disable run condition pushdown for RPR windows diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index 90275e25872..b67c35af39a 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -2453,6 +2453,17 @@ find_window_run_conditions(Query *subquery, AttrNumber attno, wclause = (WindowClause *) list_nth(subquery->windowClause, wfunc->winref - 1); + /* + * If a DEFINE clause exists, we cannot push down a run condition. In the + * case, a window partition (or frame) is divided into multiple reduced + * frames and each frame should be evaluated to the end of the partition + * (or full frame end). This means we cannot apply the run condition + * optimization because it stops evaluation window functions in certain + * cases. + */ + if (wclause->defineClause != NIL) + return false; + req.type = T_SupportRequestWFuncMonotonic; req.window_func = wfunc; req.window_clause = wclause; diff --git a/src/test/regress/expected/rpr_base.out b/src/test/regress/expected/rpr_base.out index ae6d9c9b937..a7c536625f1 100644 --- a/src/test/regress/expected/rpr_base.out +++ b/src/test/regress/expected/rpr_base.out @@ -2465,7 +2465,9 @@ WHERE cnt > 0 ORDER BY id; id | val | cnt ----+-----+----- -(0 rows) + 2 | 20 | 2 + 4 | 40 | 1 +(2 rows) -- Nested subqueries SELECT * -- 2.50.1 (Apple Git-155)