postgresql/src/backend
Richard Guo 1132af22cf Fix HAVING-to-WHERE pushdown for simple-CASE form
Commit f76686ce7 added a walker that detects when a HAVING clause uses
a collation that conflicts with the GROUP BY's nondeterministic
collation, keeping such clauses in HAVING.  The walker uses
exprInputCollation() to identify each ancestor's comparison collation,
but missed the simple-CASE case: parse analysis builds each WHEN as
OpExpr(CaseTestExpr op val), where CaseTestExpr is a placeholder for
the arg, while the actual arg expression sits at cexpr->arg, outside
the OpExpr that carries the comparison's inputcollid.  A GROUP Var at
cexpr->arg was therefore visited with the WHEN's inputcollid absent
from the ancestor stack, the conflict went undetected, and the clause
was wrongly pushed to WHERE.

Fix by handling simple CASE explicitly: before walking cexpr->arg,
push every WHEN's inputcollid onto the ancestor stack so a GROUP Var
at the arg is checked against the same collations the WHEN comparisons
would apply.  Then walk the WHEN bodies and defresult under the
unchanged stack, where their own collation contexts are picked up by
the default path.

Back-patch to v18 only; this fix extends the walker added by commit
f76686ce7 and inherits its dependency on the v18 RTE_GROUP mechanism.

Author: SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com>
Reviewed-by: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/CAHg+QDcqPdd=2V0PQ_oNYj50OUeqSqznqFaYtP3RdokLBDXBqw@mail.gmail.com
Backpatch-through: 18
2026-05-08 10:59:13 +09:00
..
access Fix nbtree skip array parallel alloc accounting. 2026-04-29 11:22:21 -04:00
archive Update copyright for 2025 2025-01-01 11:21:55 -05:00
backup Fix incorrect errno in OpenWalSummaryFile() 2026-02-03 11:25:14 +09:00
bootstrap Remove unnecessary (char *) casts [mem] 2025-02-12 08:50:13 +01:00
catalog Don't call CheckAttributeType() with InvalidOid on dropped cols 2026-04-23 21:28:59 +03:00
commands Allow ALTER INDEX .. ATTACH PARTITION to validate a parent index 2026-04-22 10:34:33 +09:00
executor Fix incorrect logic for hashed IN / NOT IN with non-strict operators 2026-04-24 14:03:41 +12:00
foreign Track the number of presorted outer pathkeys in MergePath 2025-05-08 18:21:32 +09:00
jit jit: No backport::SectionMemoryManager for LLVM 22. 2026-04-03 14:58:59 +13:00
lib Correct list of files in src/backend/lib/README 2025-06-27 09:31:23 +09:00
libpq Fix build breakage on Solaris-alikes with late-model GCC. 2025-07-23 15:44:29 -04:00
main Avoid possible crash within libsanitizer. 2025-11-05 11:09:30 -05:00
nodes Fix internal error from CollateExpr in SQL/JSON DEFAULT expressions 2025-10-09 01:07:52 -04:00
optimizer Fix HAVING-to-WHERE pushdown for simple-CASE form 2026-05-08 10:59:13 +09:00
parser Fix attnum remapping in generateClonedExtStatsStmt() 2026-04-30 11:05:29 -04:00
partitioning Strip PlaceHolderVars from partition pruning operands 2026-04-09 16:43:28 +09:00
po Translation updates 2026-02-23 13:53:35 +01:00
port Don't treat EINVAL from semget() as a hard failure. 2025-08-13 11:59:47 -04:00
postmaster Fix orphaned processes when startup process fails during PM_STARTUP 2026-04-21 09:40:03 +09:00
regex Another unintentional behavior change in commit e9931bfb75. 2025-04-16 16:49:42 -07:00
replication Flush statistics during idle periods in parallel apply worker. 2026-04-20 10:23:22 +05:30
rewrite Fix UPDATE/DELETE ... WHERE CURRENT OF on a table with virtual columns. 2026-04-22 11:50:18 +01:00
snowball Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
statistics Fix set of issues with extended statistics on expressions 2026-03-02 09:38:40 +09:00
storage Mark modified the FSM buffer as dirty during recovery 2026-05-03 20:27:36 +03:00
tcop Fix slotsync worker blocking promotion when stuck in wait 2026-04-08 11:23:13 +09:00
tsearch Prevent some buffer overruns in spell.c's parsing of affix files. 2026-04-22 12:02:15 -04:00
utils Consider collation when proving uniqueness from unique indexes 2026-05-05 10:26:17 +09:00
.gitignore
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
Makefile Fix build inconsistency due to the generation of wait-event code 2026-02-02 08:02:59 +09:00
meson.build Update copyright for 2025 2025-01-01 11:21:55 -05:00
nls.mk Return yyparse() result not via global variable 2025-01-24 06:55:39 +01:00