Re: track generic and custom plans in pg_stat_statements

Ilia Evdokimov <ilya.evdokimov@tantorlabs.com>

From: Ilia Evdokimov <ilya.evdokimov@tantorlabs.com>
To: Sami Imseih <samimseih@gmail.com>
Cc: Greg Sabino Mullane <htamfids@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-03-10T11:01:41Z
Lists: pgsql-hackers
On 06.03.2025 18:04, Sami Imseih wrote:
>> 2. Should we add Assert(kind == PGSS_EXEC) at this place  to ensure that
>> generic_plan_calls and custom_plan_calls are only incremented when
>> appropriate?
>>
>>
>> I don't think an assert is needed here. There is an assert at the start of
>> the block for PGSS_EXEC and PGSS_PLAN, but cplan is only available
>> in the executor.


You're right! Moreover, I didn't account for the fact that we pass NULL 
to pgss_ProcessUtility. In that case, Assert shouldn't be here.

I don't quite understand why do we need to differentiate between 
PLAN_CACHE_STATUS_GENERIC_PLAN_BUILD and 
PLAN_CACHE_STATUS_GENERIC_PLAN_REUSE? We could simply keep 
PLAN_CACHE_STATUS_GENERIC_PLAN_REUSE. I don't think users would see much 
of a difference in either pg_stat_statements or EXPLAIN.

As for EXPLAIN, maybe we should include this in VERBOSE mode?

--
Best regards,
Ilia Evdokimov,
Tantor Labs LLC.

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