agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
pgsql: postgres_fdw: Fix issues with statistics import.
2+ messages / 1 participants
[nested] [flat]

* pgsql: postgres_fdw: Fix issues with statistics import.
@ 2026-09-04 09:42  Etsuro Fujita <efujita@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

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

postgres_fdw: Fix issues with statistics import.

When analyzing a foreign table pointing to a partitioned or inherited
table on the remote server, this method just imported relpages and
reltuples for the parent table from the remote pg_class, causing a
discrepancy or an error in results compared to the sampling method.

* In the partitioning case, while the sampling method sets relpages=0,
  this method set relpages=-1.  (For reltuples, the results of both
  methods match.)
* In the inheritance case, while the sampling method sets
  reltuples=(# of rows in the parent and child tables), this method set
  reltuples=(# of rows in the parent table).  (For relpages, the results
  of both methods match.)

As relpages and reltuples are used for costing foreign paths, these
would lead to incorrect plans or plan changes depending on the method.
To fix, do the following:

* For the partitioning case, modify postgres_fdw to set relpages=0 to
  match the sampling method.
* For the inheritance case, we could also modify it to set the correct
  reltuples value by fetching reltuples for the child tables as well,
  but 1) the change isn't small, and 2) table inheritance hasn't been
  used that much these days, so fix by disabling this method.

While at it, adjust comments and docs slightly.

Oversight in commit 28972b6fc.

Author: Etsuro Fujita <etsuro.fujita@gmail.com>
Discussion: https://postgr.es/m/CAPmGK173b2Xvyoeq%3DY7L09H%2BajgMgxC2fYe%3D7CCunZz8tGTfFA%40mail.gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6a857156827b6a938bd02b9bf7281e7b71dfd088

Modified Files
--------------
contrib/postgres_fdw/deparse.c                 | 11 ++--
contrib/postgres_fdw/expected/postgres_fdw.out | 27 +++++++++
contrib/postgres_fdw/postgres_fdw.c            | 79 ++++++++++++++++++--------
contrib/postgres_fdw/sql/postgres_fdw.sql      | 17 ++++++
doc/src/sgml/postgres-fdw.sgml                 |  5 +-
5 files changed, 108 insertions(+), 31 deletions(-)



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

* pgsql: postgres_fdw: Fix issues with statistics import.
@ 2026-09-04 09:42  Etsuro Fujita <efujita@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

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

postgres_fdw: Fix issues with statistics import.

When analyzing a foreign table pointing to a partitioned or inherited
table on the remote server, this method just imported relpages and
reltuples for the parent table from the remote pg_class, causing a
discrepancy or an error in results compared to the sampling method.

* In the partitioning case, while the sampling method sets relpages=0,
  this method set relpages=-1.  (For reltuples, the results of both
  methods match.)
* In the inheritance case, while the sampling method sets
  reltuples=(# of rows in the parent and child tables), this method set
  reltuples=(# of rows in the parent table).  (For relpages, the results
  of both methods match.)

As relpages and reltuples are used for costing foreign paths, these
would lead to incorrect plans or plan changes depending on the method.
To fix, do the following:

* For the partitioning case, modify postgres_fdw to set relpages=0 to
  match the sampling method.
* For the inheritance case, we could also modify it to set the correct
  reltuples value by fetching reltuples for the child tables as well,
  but 1) the change isn't small, and 2) table inheritance hasn't been
  used that much these days, so fix by disabling this method.

While at it, adjust comments and docs slightly.

Oversight in commit 28972b6fc.

Author: Etsuro Fujita <etsuro.fujita@gmail.com>
Discussion: https://postgr.es/m/CAPmGK173b2Xvyoeq%3DY7L09H%2BajgMgxC2fYe%3D7CCunZz8tGTfFA%40mail.gmail.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/f4012672bb2e5f1b0a4641826e14e9d209049dea

Modified Files
--------------
contrib/postgres_fdw/deparse.c                 |  11 ++-
contrib/postgres_fdw/expected/postgres_fdw.out |  27 +++++++
contrib/postgres_fdw/postgres_fdw.c            | 100 +++++++++++++------------
contrib/postgres_fdw/sql/postgres_fdw.sql      |  17 +++++
doc/src/sgml/postgres-fdw.sgml                 |   5 +-
5 files changed, 108 insertions(+), 52 deletions(-)



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


end of thread, other threads:[~2026-09-04 09:42 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-09-04 09:42 pgsql: postgres_fdw: Fix issues with statistics import. Etsuro Fujita <efujita@postgresql.org>
2026-09-04 09:42 pgsql: postgres_fdw: Fix issues with statistics import. 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