PG Bug reporting form <noreply@postgresql.org> writes:
> Removing the last/only inheritance child from a table using ALTER TABLE NO
> INHERIT leaves orphaned statistics behind that ANALYZE doesn't remove.
> Original customer complaint on 10.16, but 15devel has the same issue.
Good catch. I imagine DETACH PARTITION has related issues?
It seems like there are basically two ways to fix this:
1. Make ALTER TABLE NO INHERIT/DETACH PARTITION get rid of
no-longer-wanted stats.
2. Make ANALYZE check for and remove any inappropriate stats.
I'm kind of inclined to prefer #1, on the grounds that #2 would
add almost-always-useless cycles to every ANALYZE run forevermore.
On the other hand, #2 seems a bit more robust, in that we'd not
have to remember to consider this issue every time somebody invents
a new flavor of DDL that affects these things.
Thoughts?
regards, tom lane