Re: Cached plan can stay stale indefinitely when an invalidation for a planner-added dependency arrives during planning

From: shihao zhong <zhong950419(at)gmail(dot)com>
To: zxlmgsps2(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Cached plan can stay stale indefinitely when an invalidation for a planner-added dependency arrives during planning
Date: 2026-12-04 04:17:07
Message-ID: CAGRkXqSfWRMekT29SosEcLmMs1ksQboOGpHtYvLVBBsxqws5=Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi Xinlei,

On Thu, Oct 22, 2026, Xinlei Zhang wrote:
> On the current code, the 15 differential checks of the five paused
> cases fail, and the other 27 checks pass, including all the controls.

I see the same on master and 17. Attached is a fix as 0001. Your test
is 0002, renumbered to 018. The fix marks a new generic plan
invalid if any invalidation arrived while planning, so the next
execution replans.

The cost is extra replans on busy clusters, since the counter also
moves for other databases. GetCachedExpression() has the same gap and
is not fixed here. The same race was also reported in [1].

[1]
https://www.postgresql.org/message-id/1FFB31CC912EA785+202611101555356917593@vastdata.com.cn

Regards,
Shihao

Attachment Content-Type Size
0001-Don-t-trust-a-generic-plan-built-while-invalidations.patch text/x-patch 3.1 KB
0002-Add-tests-for-stale-cached-plans-after-concurrent-in.patch text/x-patch 11.7 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message shihao zhong 2026-12-04 04:17:54 Re: postgres_fdw: semi-join pushdown generates invalid remote SQL ("missing FROM-clause entry") with a nested correlated subquery
Previous Message shihao zhong 2026-12-04 03:49:32 Re: parse_ident rejects a U& quoted identifier in strict mode