Re: use of SPI by postgresImportForeignStatistics

From: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
To: Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: use of SPI by postgresImportForeignStatistics
Date: 2026-08-03 22:47:50
Message-ID: CADkLM=exCGzyPMYxtHiuL0fr6Zqu4YWwcuiXvMMTBeHE_Fbr4g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Jul 18, 2026 at 2:59 PM Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com>
wrote:

> On Fri, Jul 17, 2026 at 6:59 PM Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com>
> wrote:
> > Here is a (further) cleanup:
> >
> > postgres_fdw passes the remote-server version, which is of type int,
> > to the new stats-import functions, using UInt32GetDatum not
> > Int32GetDatum. This is completely harmless because the version is 1)
> > positive and 2) currently ignored in those functions, but let's modify
> > that code to use Int32GetDatum for consistency. Attached is a small
> > patch for that. I'll push and back-patch it if no objections.
>
> Pushed and backpatched to v19.
>
> Best regards,
> Etsuro Fujita
>

There has been some time for v19 dust to settle, so I've taken the work I
had done in the v2 patch set above, re-based that, and modified the end
result to use named parameters over arg arrays of differing lengths
depending on the purpose per Fujita-san's work, and tried to keep those
changes in the same very small layered steps for easier reviewing.

Patches 0001-0003: Rename the argnum enum values to have a common prefix
(RELARG_, ATTARG_, EXTARG_)

Patch 0004: Alter the stats_check_* function signatures to stop using a
full fcinfo and instead use a NullableDatum array.

Patch 0005-0007: Replace full FunctionCallInfo parameters on
*_statistics_update() with just a NullableDatum arg array.

Patch 0008: Refactor stats_fill_fcinfo_from_arg_pairs() to use
NullableDatum array instead of full fcinfo.

Patch 0009: Stop treating "version" as a special-case parameter and add it
to the StatsArgInfo arrays.

Patch 0010: Build on 0004 and change from NullableDatum arg array + index,
and instead use individual NullableDatum values+names.

Patch 0011: Change the "internal" update functions to stop using the arg
arrays (of which some values are now empty because we've already resolved
the relation oid, etc) and instead use named NullableDatum parameters, like
the import_*_statistics() functions.

Path 0012: Unify some common operations in new utility functions
stats_check_recovery() and stats_check_lock_relation(). I consider these
function names to be placeholders until something more evocative comes
along.

Patch 0013: There isn't much need for relation_statistics_update_internal()
and relation_statistics_update() so fold the parameter checks into
pg_restore_relation_stats(), and combine what's left of the two functions
into relation_statistics_update().

Patch 0014: Same as 0013, but but attribute stats.

Patch 0015: There is no equivalent 0013/0014 for extended stats that brings
the same clarity, so make a documentation note of that.

Attachment Content-Type Size
v3-0002-Rename-attribute_stats_argnum-enumeriations.patch application/octet-stream 19.8 KB
v3-0004-Stop-using-fcinfo-in-stats_check-functions.patch application/octet-stream 10.5 KB
v3-0001-Rename-relation_stats_argnum-enumeriations.patch application/octet-stream 5.7 KB
v3-0005-Make-relation_statistics_update-stop-using-fcinfo.patch application/octet-stream 3.1 KB
v3-0003-Rename-extended-stats-enumerations.patch application/octet-stream 28.1 KB
v3-0006-Make-attribute_statistics_update-stop-using-fcinf.patch application/octet-stream 9.0 KB
v3-0009-Remove-check-and-ignore-of-version-parameter-in-s.patch application/octet-stream 7.0 KB
v3-0007-Make-extended_statistics_update-stop-using-fcinfo.patch application/octet-stream 6.7 KB
v3-0010-Decouple-stats_check_-functions-from-StatsArgInfo.patch application/octet-stream 13.0 KB
v3-0008-Change-stats_fill_fcinfo_from_arg_pairs-to-Nullab.patch application/octet-stream 11.4 KB
v3-0011-Swtich-internal-statistics-update-functions-to-us.patch application/octet-stream 24.7 KB
v3-0012-Create-stats_util-functions-for-recovery-check-ta.patch application/octet-stream 9.6 KB
v3-0013-Refactor-relation_stats-update-functions.patch application/octet-stream 6.4 KB
v3-0014-Refactor-attribute_stats-update-functions.patch application/octet-stream 12.1 KB
v3-0015-Doc-explain-extended-stats-functions.patch application/octet-stream 1.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2026-08-03 22:53:06 Re: Support UUIDv6 in uuid_extract_timestamp()
Previous Message Sami Imseih 2026-08-03 22:46:37 Re: Add pg_stat_kind_info system view