> On 23 Mar 2026, at 22:58, Merlin Moncure <mmoncure@gmail.com> wrote:
> On Thu, Mar 19, 2026 at 1:09 AM Andrei Lepikhov <lepihov@gmail.com> wrote:
> Poking around more, I see that the bad plans are related to bloat. A simple REINDEX of one of the indexes made the
problemdisappear; however, what's odd is that the estimates didn't really change although the net plan cost certainly
did. It's also worth noting ANALYZE doesn't help, only REINDEX does.
We already have plan-freezing and plan-hinting extensions. If I understand you correctly, it makes sense to invent a
statistics-freezingmodule right now. I think such a module will be quite simple - is it a good crutch for you?
Also, we have some stuff already to work out your case someday:
1. Postgres already scans indexes during planning to improve estimations of inequality clauses
(get_actual_variable_range).Here may be a way to estimate the bloat effect. Not sure how to do it, but allowing index
AMto read the page number of the returned tuple, you might, in principle, detect anomalies in the index.
2. We are quite close to vacuum statistics and detailed index statistics. This is also a way to estimate issues of
stalestatistics/bloated indexes and decide on the scan type.
So, keep the community posted and provide more real-life examples to build up a proper solution.
Andrei,
pgEdge