postgresql/src/include
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
..
access Do a tiny bit of header file maintenance 2025-09-30 12:28:29 +02:00
archive Update copyright for 2025 2025-01-01 11:21:55 -05:00
backup Add backup_type column to pg_stat_progress_basebackup. 2025-08-05 10:50:45 -07:00
bootstrap Allow redeclaration of typedef yyscan_t 2025-09-12 08:16:00 +02:00
catalog Add GROUP BY ALL. 2025-09-29 16:55:17 -04:00
commands Update various forward declarations to use typedef 2025-09-15 11:04:10 +02:00
common Update various forward declarations to use typedef 2025-09-15 11:04:10 +02:00
datatype Avoid using timezone Asia/Manila in regression tests. 2025-01-20 15:47:53 -05:00
executor Update various forward declarations to use typedef 2025-09-15 11:04:10 +02:00
fe_utils Allow redeclaration of typedef yyscan_t 2025-09-12 08:16:00 +02:00
foreign Improve ExplainState type handling in header files 2025-09-15 11:04:10 +02:00
jit jit: Fix type used for Datum values in LLVM IR. 2025-09-17 13:38:35 +12:00
lib Remove PointerIsValid() 2025-09-24 15:17:20 +02:00
libpq Remove hbaPort type 2025-09-15 11:04:10 +02:00
mb With GB18030, prevent SIGSEGV from reading past end of allocation. 2025-05-05 04:52:04 -07:00
nodes Add IGNORE NULLS/RESPECT NULLS option to Window functions. 2025-10-03 09:47:36 +09:00
optimizer Update various forward declarations to use typedef 2025-09-15 11:04:10 +02:00
parser Add IGNORE NULLS/RESPECT NULLS option to Window functions. 2025-10-03 09:47:36 +09:00
partitioning Update various forward declarations to use typedef 2025-09-15 11:04:10 +02:00
pch meson: Increase minimum version to 0.57.2 2025-07-02 11:14:53 +02:00
port Remove traces of support for Sun Studio compiler 2025-09-12 07:39:05 +02:00
portability Update copyright for 2025 2025-01-01 11:21:55 -05:00
postmaster Create a separate file listing backend types 2025-09-26 15:21:49 +02:00
regex Update copyright for 2025 2025-01-01 11:21:55 -05:00
replication Make some use of anonymous unions [reorderbuffer xact_time] 2025-09-30 12:35:50 +02:00
rewrite Update various forward declarations to use typedef 2025-09-15 11:04:10 +02:00
snowball Update to latest Snowball sources. 2025-02-18 21:13:54 -05:00
statistics Stats: use schemaname/relname instead of regclass. 2025-03-25 11:16:06 -07:00
storage Remove PointerIsValid() 2025-09-24 15:17:20 +02:00
tcop Update various forward declarations to use typedef 2025-09-15 11:04:10 +02:00
tsearch Update copyright for 2025 2025-01-01 11:21:55 -05:00
utils Rename pg_builtin_integer_constant_p to pg_integer_constant_p 2025-09-30 21:15:46 +02:00
.gitignore Use <stdint.h> and <inttypes.h> for c.h integers. 2024-12-04 15:05:38 +13:00
c.h Rename pg_builtin_integer_constant_p to pg_integer_constant_p 2025-09-30 21:15:46 +02:00
fmgr.h Change fmgr.h typedefs to use original names 2025-09-15 11:04:10 +02:00
funcapi.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
getopt_long.h IWYU widely useful pragmas 2025-01-15 18:57:53 +01:00
Makefile Clean up newly added guc_tables.inc.c 2025-09-04 17:25:43 +02:00
meson.build meson: add and use stamp files for generated headers 2025-08-11 15:18:23 -04:00
miscadmin.h Revert function to get memory context stats for processes 2025-05-23 15:44:54 +02:00
pg_config.h.in aio: Combine io_uring memory mappings, if supported 2025-07-07 22:57:07 -04:00
pg_config_manual.h Make type Datum be 8 bytes wide everywhere. 2025-08-13 17:18:22 -04:00
pg_getopt.h IWYU widely useful pragmas 2025-01-15 18:57:53 +01:00
pg_trace.h IWYU widely useful pragmas 2025-01-15 18:57:53 +01:00
pgstat.h Don't include execnodes.h in replication/conflict.h 2025-09-25 14:52:41 +02:00
pgtar.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
pgtime.h Seek zone abbreviations in the IANA data before timezone_abbreviations. 2025-01-16 14:11:19 -05:00
port.h Add timingsafe_bcmp(), for constant-time memory comparison 2025-04-02 15:32:40 +03:00
postgres.h Grab the low-hanging fruit from forcing USE_FLOAT8_BYVAL to true. 2025-08-13 17:18:22 -04:00
postgres_ext.h Move pg_int64 back to postgres_ext.h 2025-09-16 10:48:56 +02:00
postgres_fe.h IWYU widely useful pragmas 2025-01-15 18:57:53 +01:00
varatt.h Convert varatt.h access macros to static inline functions. 2025-08-05 17:01:25 +02:00
windowapi.h Add IGNORE NULLS/RESPECT NULLS option to Window functions. 2025-10-03 09:47:36 +09:00