]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix IGNORE NULLS nullness cache for volatile window arguments.
authorTatsuo Ishii <ishii@postgresql.org>
Mon, 18 May 2026 03:09:37 +0000 (12:09 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Mon, 18 May 2026 03:09:37 +0000 (12:09 +0900)
commit26269fe3c83beed1601e3bd156a98cf7696e9e08
tree6bfcdd8322d8b7f36a19782c995d4cf1ba451ea9
parente7b416b2fa444ca93d0ef1bd22b02747255733f7
Fix IGNORE NULLS nullness cache for volatile window arguments.

The IGNORE NULLS implementation caches whether a window function argument
evaluated to NULL or NOT NULL for a given partition row.  That is safe for
ordinary expressions, but not for volatile expressions, where evaluating the
same argument on the same row can produce a different NULL/NOT NULL result
later.

This could produce wrong results in two ways.  A row previously cached as
NULL could be skipped even though a later evaluation would return NOT NULL.
Conversely, a row cached as NOT NULL could be chosen as the target row, then
re-evaluated to fetch the actual value and return NULL.

Make the nullness cache conditional per argument.  Do not use it for
arguments containing volatile functions or subplans, following the same
conservative approach used for moving window aggregates.  Also avoid
re-evaluating non-cacheable partition arguments after the scan has already
found the target row.

Add regression tests covering volatile arguments and subplan arguments with
IGNORE NULLS.

Author: Chao Li <lic@highgo.com>
Reviewed-by: Tatsuo Ishii <ishii@postgresql.org>
Discussion: https://postgr.es/m/42B42506-6972-4266-8422-FB73E61D9DA7@gmail.com
src/backend/executor/nodeWindowAgg.c
src/test/regress/expected/window.out
src/test/regress/sql/window.sql