postgres-github.git / summary / log / commit / refs

commit    c1408956e393958cc93ef0dd622de406c7f3b8da
Author:   Richard Guo <rguo@postgresql.org>
Date:     Thu Apr 09 07:41:31 2026 +0000

    Strip PlaceHolderVars from partition pruning operands
    
    When pulling up a subquery, its targetlist items may be wrapped in
    PlaceHolderVars to enforce separate identity or as a result of outer
    joins.  This causes any upper-level WHERE clauses referencing these
    outputs to contain PlaceHolderVars, which prevents partprune.c from
    recognizing that they match partition key columns, defeating partition
    pruning.
    
    To fix, strip PlaceHolderVars from operands before comparing them to
    partition keys.  A PlaceHolderVar with empty phnullingrels appearing
    in a relation-scan-level expression is effectively a no-op, so
    stripping it is safe.  This parallels the existing treatment in
    indxpath.c for index matching.
    
    In passing, rename strip_phvs_in_index_operand() to strip_noop_phvs()
    and move it from indxpath.c to placeholder.c, since it is now a
    general-purpose utility used by both index matching and partition
    pruning code.
    
    Back-patch to v18.  Although this issue exists before that, changes in
    that version made it common enough to notice.  Given the lack of field
    reports for older versions, I am not back-patching further.  In the
    v18 back-patch, strip_phvs_in_index_operand() is retained as a thin
    wrapper around the new strip_noop_phvs() to avoid breaking third-party
    extensions that may reference it.
    
    Reported-by: Cándido Antonio Martínez Descalzo <candido@ninehq.com>
    Diagnosed-by: David Rowley <dgrowleyml@gmail.com>
    Author: Richard Guo <guofenglinux@gmail.com>
    Discussion: https://postgr.es/m/CAH5YaUwVUWETTyVECTnhs7C=CVwi+uMSQH=cOkwAUqMdvXdwWA@mail.gmail.com
    Backpatch-through: 18

[parent: e1cc57fabd6c]