Re: [PG19][PATCH] Make postgres_fdw statistics import atomic

From: Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com>
To: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Nikolay Samokhvalov <nik(at)postgres(dot)ai>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, ashutosh(dot)bapat(dot)oss(at)gmail(dot)com
Subject: Re: [PG19][PATCH] Make postgres_fdw statistics import atomic
Date: 2026-09-19 10:55:48
Message-ID: CAPmGK15FgPgLVZmdqesk_F=zaxyaG9C4NR-10a_DfvCebNZNQA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Sep 19, 2026 at 2:00 PM Corey Huinker <corey(dot)huinker(at)gmail(dot)com> wrote:
>>
>> What is the defense of making all these warnings rather than errors? It's one
>> thing to e.g. warn that analyze skipped a relation due to locks, but doing
>> some catalog updates but not doing everything that the catalog updates
>> depended on seems like a really bad idea. Transactions exist for a reason...
>
> This is more an explanation than a defense, but here it goes...

Thanks for the detailed explanation!

> That's the explanation, what follows is a recap of options of what we can do in the future.
>
> That decision of the analyze.c code to leave existing stats as-is when it gets an empty table sample is curious to me, as I'm not sure how ANALYZE could ever reflect when a foreign table is actually empty once it has been populated at least once, and if that's genuinely the case then perhaps we should address that, but that would have implications outside of this feature, so I'm highly reluctant to do that.

Me too. Users should observe the restrictions when using
postgres_fdw, not just this feature.

> I can foresee several possible courses of action if we choose to reopen this item.
>
> 1. Do nothing, as this is a corner case resulting from a misdesigned foreign table and a remote table in an explicitly unsupported state (modified to empty but not analyzed), and the situation will resolve itself when the remote table is repopulated, or analyzed, or the column data types are brought into alignment, whichever comes first.

+1

> 2. Consider whether do_analyze_rel should do something (like clear the pg_statistic rows for the relation) in the case where numrows returned from the acquirefunc is zero.

I also thought this option; it would make things logically clean, but
I'm not sure we really need to do so, because in that case we set
reltuples=0 in pg_class, which makes the planner effectively ignore
the remaining attribute stats. See set_baserel_size_estimates(); if
reltuples=0, we have rel->tuples=0, so whatever value
clauselist_selectivity() calculates/returns based on the attribute
stats, rel->rows (the estimated number of output tuples from the base
relation) is set to zero.

Best regards,
Etsuro Fujita

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Mats Kindahl 2026-09-19 11:51:17 Re: pg_rewind does not rewind diverging timelines
Previous Message Etsuro Fujita 2026-09-19 10:32:39 Re: Several issues with postgres_fdw stats import