postgres/src/backend/utils
Tatsuo Ishii 25a30bbd42 Add IGNORE NULLS/RESPECT NULLS option to Window functions.
Add IGNORE NULLS/RESPECT NULLS option (null treatment clause) to lead,
lag, first_value, last_value and nth_value window functions.  If
unspecified, the default is RESPECT NULLS which includes NULL values
in any result calculation. IGNORE NULLS ignores NULL values.

Built-in window functions are modified to call new API
WinCheckAndInitializeNullTreatment() to indicate whether they accept
IGNORE NULLS/RESPECT NULLS option or not (the API can be called by
user defined window functions as well).  If WinGetFuncArgInPartition's
allowNullTreatment argument is true and IGNORE NULLS option is given,
WinGetFuncArgInPartition() or WinGetFuncArgInFrame() will return
evaluated function's argument expression on specified non NULL row (if
it exists) in the partition or the frame.

When IGNORE NULLS option is given, window functions need to visit and
evaluate same rows over and over again to look for non null rows. To
mitigate the issue, 2-bit not null information array is created while
executing window functions to remember whether the row has been
already evaluated to NULL or NOT NULL. If already evaluated, we could
skip the evaluation work, thus we could get better performance.

Author: Oliver Ford <ojford@gmail.com>
Co-authored-by: Tatsuo Ishii <ishii@postgresql.org>
Reviewed-by: Krasiyan Andreev <krasiyan@gmail.com>
Reviewed-by: Andrew Gierth <andrew@tao11.riddles.org.uk>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: David Fetter <david@fetter.org>
Reviewed-by: Vik Fearing <vik@postgresfriends.org>
Reviewed-by: "David G. Johnston" <david.g.johnston@gmail.com>
Reviewed-by: Chao Li <lic@highgo.com>
Discussion: https://postgr.es/m/flat/CAGMVOdsbtRwE_4+v8zjH1d9xfovDeQAGLkP_B6k69_VoFEgX-A@mail.gmail.com
2025-10-03 09:47:36 +09:00
..
activity Fix typo in pgstat_relation.c header comment 2025-10-01 00:23:38 +13:00
adt Add IGNORE NULLS/RESPECT NULLS option to Window functions. 2025-10-03 09:47:36 +09:00
cache Remove PointerIsValid() 2025-09-24 15:17:20 +02:00
error Remove PointerIsValid() 2025-09-24 15:17:20 +02:00
fmgr Change fmgr.h typedefs to use original names 2025-09-15 11:04:10 +02:00
hash Remove dynahash.h 2025-09-10 14:11:50 +09:00
init Create a separate file listing backend types 2025-09-26 15:21:49 +02:00
mb Generate EUC_CN mappings from gb18030-2022.ucm 2025-10-02 12:36:24 +07:00
misc Ensure guc_tables.o's dependency on guc_tables.inc.c is known. 2025-09-24 12:28:20 -04:00
mmgr Remove PointerIsValid() 2025-09-24 15:17:20 +02:00
resowner Make type Datum be 8 bytes wide everywhere. 2025-08-13 17:18:22 -04:00
sort Avoid including tableam.h and xlogreader.h in nbtree.h 2025-08-14 17:48:46 +02:00
time Revert GetTransactionSnapshot() to return historic snapshot during LR 2025-08-22 13:07:46 +03:00
.gitignore Generate GUC tables from .dat file 2025-09-03 09:45:17 +02:00
errcodes.txt Update copyright for 2025 2025-01-01 11:21:55 -05:00
Gen_dummy_probes.pl Update copyright for 2025 2025-01-01 11:21:55 -05:00
Gen_fmgrtab.pl Update copyright for 2025 2025-01-01 11:21:55 -05:00
generate-errcodes.pl Update copyright for 2025 2025-01-01 11:21:55 -05:00
Makefile Generate GUC tables from .dat file 2025-09-03 09:45:17 +02:00
meson.build Update copyright for 2025 2025-01-01 11:21:55 -05:00
postprocess_dtrace.sed Update copyright for 2025 2025-01-01 11:21:55 -05:00
probes.d Update copyright for 2025 2025-01-01 11:21:55 -05:00