Re: Import Statistics in postgres_fdw before resorting to sampling.
Etsuro Fujita <etsuro.fujita@gmail.com>
From: Etsuro Fujita <etsuro.fujita@gmail.com>
To: Matheus Alcantara <matheusssilv97@gmail.com>
Cc: Corey Huinker <corey.huinker@gmail.com>,
Michael Paquier <michael@paquier.xyz>, Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>, pgsql-hackers@postgresql.org, jkatz@postgresql.org, nathandbossart@gmail.com
Date: 2026-01-07T02:18:04Z
Lists: pgsql-hackers
Hi Matheus,
On Wed, Jan 7, 2026 at 6:38 AM Matheus Alcantara
<matheusssilv97@gmail.com> wrote:
> + if (fdwroutine->ImportStatistics != NULL &&
> + fdwroutine->StatisticsAreImportable != NULL &&
> + fdwroutine->StatisticsAreImportable(onerel))
> + import_stats = true;
> + else
> + {
> + if (fdwroutine->AnalyzeForeignTable != NULL)
> + ok = fdwroutine->AnalyzeForeignTable(onerel,
> + &acquirefunc,
> + &relpages);
> +
> + if (!ok)
> + {
> + ereport(WARNING,
> + errmsg("skipping \"%s\" -- cannot analyze this foreign table.",
> + RelationGetRelationName(onerel)));
> + relation_close(onerel, ShareUpdateExclusiveLock);
> + return;
> + }
> + }
> +
> if (fdwroutine->AnalyzeForeignTable != NULL)
> ok = fdwroutine->AnalyzeForeignTable(onerel,
> &acquirefunc,
> &relpages);
>
> if (!ok)
> {
> ereport(WARNING,
> (errmsg("skipping \"%s\" --- cannot analyze this foreign table",
> RelationGetRelationName(onerel))));
> relation_close(onerel, ShareUpdateExclusiveLock);
> return;
> }
>
> It seems that we have the same code within the else branch after the if/else
> check, is this correct?
No. This should be something like the attached in [1]. (I didn't
look at the core changes in v6...)
Thanks!
Best regards,
Etsuro Fujita
[1] https://www.postgresql.org/message-id/CAPmGK17Dfjy_zLH1yjPqybpSueHWP7Gy_xBZXA2NpRso1qya7A%40mail.gmail.com
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
postgres_fdw: Replace buffers in RemoteAttributeMapping with pointers.
- aa1f93a3387a 19 (unreleased) landed
-
Add support for importing statistics from remote servers.
- 28972b6fc3dc 19 (unreleased) landed