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 <[email protected]> Reviewed-by: Tatsuo Ishii <[email protected]> Discussion: https://postgr.es/m/[email protected] Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/26269fe3c83beed1601e3bd156a98cf7696e9e08 Modified Files -------------- src/backend/executor/nodeWindowAgg.c | 44 +++++++++++++++++++----- src/test/regress/expected/window.out | 66 ++++++++++++++++++++++++++++++++++++ src/test/regress/sql/window.sql | 28 +++++++++++++++ 3 files changed, 130 insertions(+), 8 deletions(-)
