]> git.ipfire.org Git - thirdparty/postgresql.git/commit
postgres_fdw: Remove SPI from postgresImportForeignStatistics.
authorEtsuro Fujita <efujita@postgresql.org>
Fri, 10 Jul 2026 04:20:00 +0000 (13:20 +0900)
committerEtsuro Fujita <efujita@postgresql.org>
Fri, 10 Jul 2026 04:20:00 +0000 (13:20 +0900)
commit54cd6fc83176d7c03abf95554aef26b0b24acc7d
treee0b2a2212448b5726c0a0fc54a4d69826d9d75d1
parent5594f209c3eff6e478e1d6109094f14b59bd3dce
postgres_fdw: Remove SPI from postgresImportForeignStatistics.

Previously, this function imported remote statistics by executing SQL
functions like pg_restore_relation_stats and pg_restore_attribute_stats
via SPI (in read-write mode).  As the SQL functions take a schema name
and a relation name as two separate arguments, rather than a single OID
argument, if the containing schema was concurrently renamed, the
callback function would throw an error like this:

  ERROR: schema "foo" does not exist

To fix, 1) provide new interface functions to import remote statistics
that are directly callable from FDWs and take a single OID, and 2)
modify the callback function to use the interface functions instead when
importing remote statistics.

For #1, this commit does a bit of refactoring to
relation_statistics_update and attribute_statistics_update, which are
the workhorse functions for pg_restore_relation_stats and
pg_restore_attribute_stats respectively: since they also take a schema
name and a relation name, separate the guts of them into new functions
so that they take a single OID and are callable not only from the
workhorse functions but from the interface functions introduced by #1.

Oversight in commit 28972b6fc.

Reported-by: Robert Haas <robertmhaas@gmail.com>
Suggested-by: Robert Haas <robertmhaas@gmail.com>
Author: Corey Huinker <corey.huinker@gmail.com>
Co-authored-by: Etsuro Fujita <etsuro.fujita@gmail.com>
Discussion: https://postgr.es/m/CA%2BTgmoYqMtWb4zLUkT98oFnEkJ%3DWz0Pw-ggDJrp9wnSXPzUaeQ%40mail.gmail.com
Backpatch-through: 19
contrib/postgres_fdw/expected/postgres_fdw.out
contrib/postgres_fdw/postgres_fdw.c
contrib/postgres_fdw/sql/postgres_fdw.sql
doc/src/sgml/fdwhandler.sgml
src/backend/statistics/attribute_stats.c
src/backend/statistics/relation_stats.c
src/include/statistics/statistics.h