postgresql/src/include/nodes
Richard Guo 574581b50a Consider collation when proving subquery uniqueness
rel_is_distinct_for()'s RTE_SUBQUERY branch passed only the equality
operator from each join clause to query_is_distinct_for(), discarding
the operator's input collation.  query_is_distinct_for() then verified
opfamily compatibility but never checked collations, so a DISTINCT /
GROUP BY / set-op operating under one collation was trusted to prove
uniqueness for a comparison performed under an unrelated collation.
As with the recent fix in relation_has_unique_index_for(), this is
unsound for nondeterministic collations and yields wrong query results
in any optimization that consumes the proof.

Fix by carrying each clause's operator input collation into
query_is_distinct_for() and validating it at every check-site against
the subquery target expression's collation.

Back-patch to all supported branches.  query_is_distinct_for() is
declared in an installed header, so on stable branches the existing
two-list signature is retained as a thin wrapper that forwards to a
new collation-aware entry point; external callers continue to receive
the historical collation-blind answer.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAMbWs4_XUUSTyzCaRjUeeahWNqi=8ZOA5Q4coi8zUVEDSBkM6A@mail.gmail.com
Backpatch-through: 14
2026-05-05 10:23:31 +09:00
..
.gitignore Automatically generate node support functions 2022-07-09 08:53:59 +02:00
bitmapset.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
execnodes.h Add EXPLAIN (IO) instrumentation for TidRangeScan 2026-04-07 23:25:05 +02:00
extensible.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
lockoptions.h Add support for INSERT ... ON CONFLICT DO SELECT. 2026-02-12 09:57:04 +00:00
makefuncs.h Allow IS JSON predicate to work with domain types 2026-03-17 15:20:22 -04:00
memnodes.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
meson.build Update copyright for 2026 2026-01-01 13:24:10 -05:00
miscnodes.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
multibitmapset.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
nodeFuncs.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
nodes.h Change copyObject() to use typeof_unqual 2026-03-13 07:06:57 +01:00
params.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
parsenodes.h Add UPDATE/DELETE FOR PORTION OF 2026-04-01 19:06:03 +02:00
pathnodes.h Consider collation when proving subquery uniqueness 2026-05-05 10:23:31 +09:00
pg_list.h Make fixed-length list building macros work in C++ 2026-03-26 08:53:13 +01:00
plannodes.h Add UPDATE/DELETE FOR PORTION OF 2026-04-01 19:06:03 +02:00
primnodes.h Fix JSON_ARRAY(query) empty set handling and view deparsing 2026-05-01 09:42:00 +09:00
print.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
queryjumble.h Mark JumbleState as a const in the post_parse_analyze hook 2026-04-07 15:22:49 +09:00
readfuncs.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
replnodes.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
subscripting.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
supportnodes.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
tidbitmap.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
value.h Update copyright for 2026 2026-01-01 13:24:10 -05:00