Yeah, that use makes sense as well, and if so then postgres_fdw would likely need to be aware of the appropriate query for several versions back - they change, not by much, but they do change. So now we'd have each query text in three places: a system view, postgres_fdw, and the bin/scripts pre-upgrade program. So I probably should consider the best way to share those in the codebase.
Attached is v2 of this patch.
New features:
* imports index statistics. This is not strictly accurate: it re-computes index statistics the same as ANALYZE does, which is to say it derives those stats entirely from table column stats, which are imported, so in that sense we're getting index stats without touching the heap. * now support extended statistics except for MCV, which is currently serialized as an difficult-to-decompose bytea field. * bare-bones CLI script pg_export_stats, which extracts stats on databases back to v12 (tested) and could work back to v10. * bare-bones CLI script pg_import_stats, which obviously only works on current devel dbs, but can take exports from older versions.