agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
pgsql: postgres_fdw: Remove SPI from postgresImportForeignStatistics.
2+ messages / 1 participants
[nested] [flat]

* pgsql: postgres_fdw: Remove SPI from postgresImportForeignStatistics.
@ 2026-07-10 04:22 Etsuro Fujita <efujita@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Etsuro Fujita @ 2026-07-10 04:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/54cd6fc83176d7c03abf95554aef26b0b24acc7d

Modified Files
--------------
contrib/postgres_fdw/expected/postgres_fdw.out |  37 +++
contrib/postgres_fdw/postgres_fdw.c            | 443 ++++++++++---------------
contrib/postgres_fdw/sql/postgres_fdw.sql      |  28 ++
doc/src/sgml/fdwhandler.sgml                   |   5 +-
src/backend/statistics/attribute_stats.c       | 174 ++++++++--
src/backend/statistics/relation_stats.c        |  86 ++++-
src/include/statistics/statistics.h            |  25 ++
7 files changed, 484 insertions(+), 314 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: postgres_fdw: Remove SPI from postgresImportForeignStatistics.
@ 2026-07-10 04:22 Etsuro Fujita <efujita@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Etsuro Fujita @ 2026-07-10 04:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/3334b0d9f25a897b8298c849d08909bdc532874a

Modified Files
--------------
contrib/postgres_fdw/expected/postgres_fdw.out |  37 +++
contrib/postgres_fdw/postgres_fdw.c            | 443 ++++++++++---------------
contrib/postgres_fdw/sql/postgres_fdw.sql      |  28 ++
doc/src/sgml/fdwhandler.sgml                   |   5 +-
src/backend/statistics/attribute_stats.c       | 174 ++++++++--
src/backend/statistics/relation_stats.c        |  86 ++++-
src/include/statistics/statistics.h            |  25 ++
7 files changed, 484 insertions(+), 314 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-07-10 04:22 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-07-10 04:22 pgsql: postgres_fdw: Remove SPI from postgresImportForeignStatistics. Etsuro Fujita <efujita@postgresql.org>
2026-07-10 04:22 pgsql: postgres_fdw: Remove SPI from postgresImportForeignStatistics. Etsuro Fujita <efujita@postgresql.org>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox