Re: track generic and custom plans in pg_stat_statements

Sami Imseih <samimseih@gmail.com>

From: Sami Imseih <samimseih@gmail.com>
To: Andrei Lepikhov <lepihov@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>, Tom Lane <tgl@sss.pgh.pa.us>, Greg Sabino Mullane <htamfids@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>, Nikolay Samokhvalov <nik@postgres.ai>, Ilia Evdokimov <ilya.evdokimov@tantorlabs.com>
Date: 2025-07-30T20:09:08Z
Lists: pgsql-hackers
> So, analysing
> pg_s_s data, it would be beneficial to determine if a generic plan is
> effective or not.

Yes, this is the point of adding these statistics to pg_s_s.

> In practice, with this knowledge, we can access the CachedPlanSource of
> the corresponding PREPARED statement via an extension and override the
> decision made in 'auto' mode. Unfortunately, we cannot obtain a pointer
> to plan cache entries for plans prepared by the extended protocol, but
> this may be possible in the future.
>
> So, I meant that the source of the plan is one important characteristic,
> and the type (custom or generic) is another, independent characteristic

The concepts of custom and generic plan types are associated with plan caches,
so they cannot have a different source. right?

--
Sami



Commits

  1. pg_stat_statements: Add counters for generic and custom plans

  2. Rename CachedPlanType to PlannedStmtOrigin for PlannedStmt

  3. Introduce field tracking cached plan type in PlannedStmt