pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Matheus Alcantara <matheusssilv97@gmail.com>
To: Corey Huinker <corey.huinker@gmail.com>
To: Etsuro Fujita <etsuro.fujita@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Cc: pgsql-hackers@postgresql.org
Cc: jkatz@postgresql.org
Cc: nathandbossart@gmail.com
Subject: Re: Import Statistics in postgres_fdw before resorting to sampling.
Date: Thu, 08 Jan 2026 16:42:47 -0300
Message-ID: <DFJGQC8ROZK0.1IVQDK0Z3H838@gmail.com> (raw)
In-Reply-To: <CADkLM=ezV0_oUCxK=A2TmaAuXvWs0+i-H8fSNU3BRY=dBuDhQQ@mail.gmail.com>
References: <CADkLM=chrYAx=X2KUcDRST4RLaRLivYDohZrkW4LLBa0iBhb5w@mail.gmail.com>
	<CAExHW5seoMNjHiZge0O=p-oF6PGsY8om4VjpzTCBsaASXZC6Fw@mail.gmail.com>
	<CADkLM=feCJrEDWCOpoxxg58J_6zX6nv+BnXufUOEZuP7bYTCbg@mail.gmail.com>
	<CADkLM=d8+FwmbH0imhPOw=VGEASL4Q8tsCFjNcnfbU7sSWm0ig@mail.gmail.com>
	<CADkLM=cVc-KUAqcm1yoDkGwMrcgCvxY3WAMpaRZVLtO9sbc+kg@mail.gmail.com>
	<aPXaeowZ6RBPlsrD@paquier.xyz>
	<CADkLM=dSJk8h+14Wi7dGGcO1168R_nCGO2EHRTcC6b2Zu0rhpg@mail.gmail.com>
	<CAPmGK15Lk0ynP_b46sgfV1pmByzWUKVQoZBSV8fbN0rKb_6AnA@mail.gmail.com>
	<CADkLM=foU7yK1rfMzqTPiQtfEOGANAS9dHE5-Js6hEXmZiKfow@mail.gmail.com>
	<CADkLM=eDJiXe58+fXiFqp8Zyrh-E28mU11U53rVGjx0AQFzBKw@mail.gmail.com>
	<CAPmGK15jEDCeMXE=EEuA5-1tC2xg5WYSjWzPGpcz+udHBT4bUA@mail.gmail.com>
	<CADkLM=fRF2w-_fMyztS0R4e9YVH8tamHXMsBBVhFsSHoJKrKXg@mail.gmail.com>
	<CAPmGK17Dfjy_zLH1yjPqybpSueHWP7Gy_xBZXA2NpRso1qya7A@mail.gmail.com>
	<CADkLM=fb=FsBLqNc14-y4na57ypywZxYb4q-zrxcaY6qQW0B2Q@mail.gmail.com>
	<CADkLM=dfuT8YgXOyoXW7nuGdOFw-sYh2uR3hQS-N66Gj_k_ytw@mail.gmail.com>
	<CAPmGK17v-qJL5j2Z25jD33vKLyhAnNppYsy5UTbEAwAeBP=vGQ@mail.gmail.com>
	<CAPmGK15iR8M55_Fi6PZyvSH5-4B-R2n2YvvhRJB8Pm2cxxrF1w@mail.gmail.com>
	<CADkLM=cVZH+SDUuvsyMHzuWTK5XkK1i_L5dgTNrgRXWN1S-syQ@mail.gmail.com>
	<CAPmGK16AQzGsEe6pD7m42AO1KRCuXQu=U_abXaAf3juCS5U+mA@mail.gmail.com>
	<CADkLM=ezV0_oUCxK=A2TmaAuXvWs0+i-H8fSNU3BRY=dBuDhQQ@mail.gmail.com>

On Wed Jan 7, 2026 at 3:04 AM -03, Corey Huinker wrote:
> Anyway, here's v8, incorporating the documentation feedback and Matheus's
> notes.
>

+CREATE FOREIGN TABLE remote_analyze_ftable (id int, a text, b bigint)
+       SERVER loopback
+       OPTIONS (table_name 'remote_analyze_table',
+                fetch_stats 'true',
+                remote_analyze 'true');

I think that it would be good also to have a test case where
remote_analyze is false. The test could manually execute an ANALYZE on
the target table and ensure that an ANALYZE on the foreign table fetch
the statistics correctly.

---

If the table don't have columns it fails to fetch the statistics with
remote_analyze=false even if the target table has statistics:
ERROR:  P0002: Failed to import statistics from remote table public.t2, no statistics found.

And if I set remote_analyze=true it fails with the following error:

postgres=# analyze t2_fdw;
ERROR:  08006: could not obtain message string for remote error
CONTEXT:  remote SQL command: SELECT DISTINCT ON (s.attname) attname,
s.null_frac, s.avg_width, s.n_distinct, s.most_common_vals,
s.most_common_freqs, s.histogram_bounds, s.correlation,
s.most_common_elems, s.most_common_elem_freqs, s.elem_count_histogram,
s.range_length_histogram, s.range_empty_frac, s.range_bounds_histogram
FROM pg_catalog.pg_stats AS s WHERE s.schemaname = $1 AND s.tablename =
$2 AND s.attname = ANY($3::text[]) ORDER BY s.attname, s.inherited DESC
LOCATION:  pgfdw_report_internal, connection.c:1037

---

If we try to run ANALYZE on a specific table column that don't exists we
get:
postgres=# analyze t(c);
ERROR:  42703: column "c" of relation "t" does not exist
LOCATION:  do_analyze_rel, analyze.c:412

With fetch_stats=false we get the same error:

postgres=# ALTER FOREIGN TABLE t_fdw OPTIONS (add fetch_stats 'false');
ALTER FOREIGN TABLE

postgres=# ANALYZE t_fdw(c);
ERROR:  42703: column "c" of relation "t_fdw" does not exist

But with fetch_stats=true we get a different error:

postgres=# ALTER FOREIGN TABLE t_fdw OPTIONS (drop fetch_stats);
ALTER FOREIGN TABLE

postgres=# ANALYZE t_fdw(c);
ERROR:  P0002: Failed to import statistics from remote table public.t, no statistics found.

Should all these errors be consistency?

---

I hope that these comments are more useful now. Thanks.

--
Matheus Alcantara
EDB: https://www.enterprisedb.com





view thread (89+ messages)  latest in thread

Message-ID: <DFJGQC8ROZK0.1IVQDK0Z3H838@gmail.com>
Permalink:  ../DFJGQC8ROZK0.1IVQDK0Z3H838@gmail.com/
Also on:    postgresql.org/message-id/DFJGQC8ROZK0.1IVQDK0Z3H838@gmail.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: matheusssilv97@gmail.com, corey.huinker@gmail.com, etsuro.fujita@gmail.com, michael@paquier.xyz, ashutosh.bapat.oss@gmail.com, jkatz@postgresql.org, nathandbossart@gmail.com
  Subject: Re: Import Statistics in postgres_fdw before resorting to sampling.
  In-Reply-To: <DFJGQC8ROZK0.1IVQDK0Z3H838@gmail.com>
  References: <CADkLM=chrYAx=X2KUcDRST4RLaRLivYDohZrkW4LLBa0iBhb5w@mail.gmail.com> <CADkLM=foU7yK1rfMzqTPiQtfEOGANAS9dHE5-Js6hEXmZiKfow@mail.gmail.com> <CADkLM=eDJiXe58+fXiFqp8Zyrh-E28mU11U53rVGjx0AQFzBKw@mail.gmail.com> <CAPmGK15jEDCeMXE=EEuA5-1tC2xg5WYSjWzPGpcz+udHBT4bUA@mail.gmail.com> <CADkLM=fRF2w-_fMyztS0R4e9YVH8tamHXMsBBVhFsSHoJKrKXg@mail.gmail.com> <CAPmGK17Dfjy_zLH1yjPqybpSueHWP7Gy_xBZXA2NpRso1qya7A@mail.gmail.com> <CADkLM=fb=FsBLqNc14-y4na57ypywZxYb4q-zrxcaY6qQW0B2Q@mail.gmail.com> <CADkLM=dfuT8YgXOyoXW7nuGdOFw-sYh2uR3hQS-N66Gj_k_ytw@mail.gmail.com> <CAPmGK17v-qJL5j2Z25jD33vKLyhAnNppYsy5UTbEAwAeBP=vGQ@mail.gmail.com> <CAPmGK15iR8M55_Fi6PZyvSH5-4B-R2n2YvvhRJB8Pm2cxxrF1w@mail.gmail.com> <CADkLM=cVZH+SDUuvsyMHzuWTK5XkK1i_L5dgTNrgRXWN1S-syQ@mail.gmail.com> <CAPmGK16AQzGsEe6pD7m42AO1KRCuXQu=U_abXaAf3juCS5U+mA@mail.gmail.com> <CADkLM=ezV0_oUCxK=A2TmaAuXvWs0+i-H8fSNU3BRY=dBuDhQQ@mail.gmail.com> <DFJGQC8ROZK0.1IVQDK0Z3H838@gmail.com>

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

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