Plan caching and serialization for reuse across executions

From: Xuan Chen <cx0222(at)vip(dot)qq(dot)com>
To: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Plan caching and serialization for reuse across executions
Date: 2025-08-16 12:32:26
Message-ID: tencent_C575540808B79A0BEB25F343724F6697C80A@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

I am currently exploring whether it is possible to cache a plan generated by the PostgreSQL planner and reuse it across later executions.

I understand that there are existing mechanisms like PREPARE/EXECUTE and CachedPlan in plancache.c, but these are tied to prepared statements and session-level usage. My interest is more on the research side:

- Is there any supported (or experimental) way to serialize a Plan or PlannedStmt structure and reload it in a future execution, bypassing the planner?
- If not, would it make sense to extend the existing CachedPlan mechanism to support serialization/deserialization, or are there known architectural reasons why this approach is discouraged?
- Any relevant references in the source code (planner, plancache.c, executor) that I should study would be very helpful.

The motivation is research-oriented: I want to experiment with plan persistence as a way to reduce planning overhead and study trade-offs of reusing cached plans.

Thanks a lot for your guidance!

Best regards,
Xuan Chen

Browse pgsql-hackers by date

  From Date Subject
Next Message Álvaro Herrera 2025-08-16 12:52:30 Re: Retail DDL
Previous Message David Rowley 2025-08-16 12:24:29 Re: Compilation issues for HASH_STATISTICS and HASH_DEBUG options