agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Etsuro Fujita <efujita@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: postgres_fdw: Fix issues with statistics import.
Date: Fri, 04 Sep 2026 09:42:10 +0000
Message-ID: <E1x2QQy-00000003R1l-3y8w@gemulon.postgresql.org> (raw)

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(-)



view thread (2+ messages)  latest in thread

Message-ID: <E1x2QQy-00000003R1l-3y8w@gemulon.postgresql.org>
Permalink:  ../E1x2QQy-00000003R1l-3y8w@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1x2QQy-00000003R1l-3y8w@gemulon.postgresql.org

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: efujita@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: postgres_fdw: Fix issues with statistics import.
  In-Reply-To: <E1x2QQy-00000003R1l-3y8w@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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