Re: Use-after-free of a shared Path in add_path()/add_partial_path()

From: Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Richard Guo <guofenglinux(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Use-after-free of a shared Path in add_path()/add_partial_path()
Date: 2026-11-23 09:22:51
Message-ID: CAM2+6=XQNEHopvwr_YWBTNuoceTiD5nx1JFBqbW05CUba_gcUQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Nov 22, 2026 at 12:49 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com> writes:
> > Richard, are you planning to take this further yourself, or should I
> > keep pushing this patch? Just want to avoid duplicated effort.
>
> This same problem was re-reported recently [1], and I rediscovered
> basically the same fix, after which Richard pointed out that it's
> the same as discussed in this thread. So I've pushed your v2-0001
> after some editorialization on the comments.

Thank you, Tom, for pushing the changes and improving the code comments.

And thank you, Richard, for reviewing the patch and directing the other
thread here.

> I did not include
> a test case, because I have zero faith that the known test cases
> are stable enough to reveal the problem after future costing
> changes. As far as I can tell, to expose the grouping_planner
> problem you need partial paths with fuzzily-equal total cost,
> such that add_path and add_partial_path will make different
> decisions based on the fact that they don't consider exactly the
> same set of secondary factors. Even then, only one of the four
> possible choice pairs leads to an observable bug. So that's just
> too brittle to be worth expending testing cycles on forevermore.
>
> regards, tom lane
>
> [1]
> https://www.postgresql.org/message-id/flat/19924-8aecd924385fafcc%40postgresql.org
>

--
*Jeevan Chalke*
*Senior Principal Engineer, Engineering Manager*
*Product Development*

enterprisedb.com <https://www.enterprisedb.com>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Dean Rasheed 2026-11-23 09:25:00 Re: MERGE fails to reject source references in NOT MATCHED BY SOURCE actions
Previous Message Bertrand Drouvot 2026-11-23 09:22:39 Fix relation statistics around transactional TRUNCATE