postgresql/src
Richard Guo ee2fa291c8 Fix wrong unsafe-flag test in check_output_expressions()
The check for window functions (point 4) guarded on the wrong bit: it
tested UNSAFE_NOTIN_DISTINCTON_CLAUSE while setting
UNSAFE_NOTIN_PARTITIONBY_CLAUSE.  Each check in this loop guards on
the same bit it is about to set, as an idempotency optimization, since
unsafeFlags[] is accumulated across the arms of a set operation and
there is no point recomputing a column's status once its bit is
present.

This is not a live bug.  When UNSAFE_NOTIN_PARTITIONBY_CLAUSE is
already set but UNSAFE_NOTIN_DISTINCTON_CLAUSE is not, the guard fails
to skip targetIsInAllPartitionLists() and recomputes it, but setting
the same bit again changes nothing.  When
UNSAFE_NOTIN_DISTINCTON_CLAUSE is already set, point 4 is skipped and
UNSAFE_NOTIN_PARTITIONBY_CLAUSE is left unset; but such a column is
already unsafe for pushdown via UNSAFE_NOTIN_DISTINCTON_CLAUSE, so the
outcome is unchanged.

To fix, test UNSAFE_NOTIN_PARTITIONBY_CLAUSE, matching the bit being
set and the pattern of the surrounding checks.

Back-patch to v15, where the buggy check was introduced.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAMbWs49Q_xnF_P2QSUyDzJ34MnrO7dh-cUAaK2HJPgSgh88NcA@mail.gmail.com
Backpatch-through: 15
2026-06-03 09:36:52 +09:00
..
backend Fix wrong unsafe-flag test in check_output_expressions() 2026-06-03 09:36:52 +09:00
bin psql: Fix issues with deferred errors in pipelines 2026-06-03 08:58:26 +09:00
common pg_test_timing: Show additional TSC clock source debug info 2026-05-16 11:51:34 -04:00
fe_utils Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
include Constistent naming for datacheckusms processes 2026-05-29 21:26:25 +02:00
interfaces Translation updates 2026-06-01 12:13:54 +02:00
makefiles Add CONCURRENTLY option to REPACK 2026-04-06 21:55:08 +02:00
pl Translation updates 2026-06-01 12:13:54 +02:00
port pg_test_timing: Show additional TSC clock source debug info 2026-05-16 11:51:34 -04:00
template Switch the semaphore API on Solaris to unnamed POSIX. 2026-03-14 14:10:32 -04:00
test psql: Fix issues with deferred errors in pipelines 2026-06-03 08:58:26 +09:00
timezone Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
tools pg_test_timing: Show additional TSC clock source debug info 2026-05-16 11:51:34 -04:00
tutorial Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
.gitignore
DEVELOPERS
Makefile Add CONCURRENTLY option to REPACK 2026-04-06 21:55:08 +02:00
Makefile.global.in Update Unicode data to CLDR 48.2 2026-04-13 11:13:36 +02:00
Makefile.shlib Restore AIX support. 2026-02-23 13:34:22 -05:00
meson.build Update copyright for 2026 2026-01-01 13:24:10 -05:00
nls-global.mk Fix update-po for the PGXS case 2025-10-16 20:21:05 +02:00