Re: Potential partition pruning regression on PostgreSQL 18

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: Cándido Antonio Martínez Descalzo <candido(at)ninehq(dot)com>, Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Potential partition pruning regression on PostgreSQL 18
Date: 2026-04-02 07:34:33
Message-ID: CAMbWs49ittTvqB50_=eNPwN3-HAJX__s3kfn5nJc3nABTUZoyQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-performance

On Thu, Apr 2, 2026 at 8:01 AM David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
> The question is, can we do the same thing in
> match_clause_to_partition_key() as we did for index clauses in
> ad66f705f. The PlaceHolderVar's phnullingrels are empty for this
> query, so I expect we just need to give the same treatment to
> partition key columns as was done for indexes columns in
> fix_indexqual_operand().

Agreed. The clauses in match_clause_to_partition_key() are always
relation-scan-level expressions, where a PHV with an empty
phnullingrels is effectively a no-op. Therefore, we can safely strip
such PHVs.

Attached is a draft patch for the fix.

Regarding backpatching, I'm inclined to only back-patch this down to
v18. This issue actually predates v18, for example, when the
partition key is a non-Var expression. A non-Var target item will be
wrapped in a PHV, causing us to fail the partition key match.
However, the changes in v18 seem to have made the issue common enough
to notice. This is very similar to the index matching case.

- Richard

Attachment Content-Type Size
v1-0001-Strip-PlaceHolderVars-from-partition-pruning-oper.patch application/octet-stream 20.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Chao Li 2026-04-02 07:28:48 Re: pg_test_timing: fix unit typo and widen diff type

Browse pgsql-performance by date

  From Date Subject
Previous Message Scott Carey 2026-04-02 07:23:43 Re: Significant performance issues with array_agg() + HashAggregate plans on Postgres 17