should num_custom_plans be reset after plan invalidation? - Mailing list pgsql-hackers

From Sami Imseih
Subject should num_custom_plans be reset after plan invalidation?
Date
Msg-id CAA5RZ0sYt1GFwMC2ysKxPFfErOj6w8UXbpo=mkx-waCsd8P5hg@mail.gmail.com
Whole thread Raw
Responses Re: should num_custom_plans be reset after plan invalidation?
List pgsql-hackers
Hi,

While examining plan caches, I noticed that when a generic plan is invalidated,
the next execution of the prepared statement still results in a
generic plan. This
is of course with the default plan_cache_mode.

This behavior might go unnoticed since plan cache invalidations are
relatively uncommon,
but I’m unsure if this is the intended design. The existing decision
to switch to
a generic plan—based on the cost average of the first five custom
plans—may no longer
be optimal after a relation is modified (e.g., when a new index is added).
Given this, resetting num_custom_plans to 0 after a plan cache invalidation
might be a better approach.

I've attached an example for reference. The fix seems straightforward,
but since generic
plans may already not handle skewed data optimally, I want to see if others have
thoughts on this being something to fix.

--
Sami Imseih
Amazon Web Services (AWS)

Attachment

pgsql-hackers by date:

Previous
From: "Daniel Verite"
Date:
Subject: Re: Add Pipelining support in psql
Next
From: Peter Geoghegan
Date:
Subject: Re: Showing primitive index scan count in EXPLAIN ANALYZE (for skip scan and SAOP scans)