Re: track generic and custom plans in pg_stat_statements - Mailing list pgsql-hackers

From Andrei Lepikhov
Subject Re: track generic and custom plans in pg_stat_statements
Date
Msg-id b3b87daa-d610-424d-8217-bc4a47dd918c@gmail.com
Whole thread Raw
In response to Re: track generic and custom plans in pg_stat_statements  (Sami Imseih <samimseih@gmail.com>)
Responses Re: track generic and custom plans in pg_stat_statements
List pgsql-hackers
On 7/30/25 21:05, Sami Imseih wrote:
>>> The term "NOT_SET" makes me itch a little bit, even if there is an
>>> existing parallel with OverridingKind.  Perhaps your proposal is OK,
>>> still how about "UNKNOWN" instead to use as term for the default?
>> +1 to "UNKNOWN".
> 
> We currently use both UNKNOWN and NOT_SET in different places.
> However, I'm okay with using UNKNOWN, and I've updated it in v16.
> 
>> But generally, classification in the PlannedStmtOrigin structure seems a
>> little strange: a generic plan has a qualitative difference from any
>> custom one. And any other plan also will be generic or custom, doesn't
>> it?
> 
> I am not sure I understand the reasoning here. Can you provide more details/
> specific examples?
Yep,
When building a generic plan, you don't apply any constant to the 
clause, such as 'x<$1'.
That means you can't use histograms or MCV statistics when building a 
custom plan. The optimiser should guess and frequently uses just a 
'magic constant', like 0.05 or 0.33 for selectivity estimation. It 
sometimes drastically reduces the quality of the plan. So, analysing 
pg_s_s data, it would be beneficial to determine if a generic plan is 
effective or not.

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

-- 
regards, Andrei Lepikhov



pgsql-hackers by date:

Previous
From: Corey Huinker
Date:
Subject: Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions
Next
From: Peter Eisentraut
Date:
Subject: Re: Support getrandom() for pg_strong_random() source