Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wZZCd-0018g3-2c for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jun 2026 19:12:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wZZCc-002HkL-1b for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jun 2026 19:12:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wZZCc-002HkC-0X for pgsql-hackers@lists.postgresql.org; Tue, 16 Jun 2026 19:12:02 +0000 Received: from mail-dl1-x1236.google.com ([2607:f8b0:4864:20::1236]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wZZCZ-00000000mbW-2X9p for pgsql-hackers@postgresql.org; Tue, 16 Jun 2026 19:12:01 +0000 Received: by mail-dl1-x1236.google.com with SMTP id a92af1059eb24-13807d2f898so5373991c88.0 for ; Tue, 16 Jun 2026 12:11:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1781637117; cv=none; d=google.com; s=arc-20240605; b=kcXInWOHzB+HRAoV3y1+B12joqTb7bn/k0zzZfu7kV1YWWB+rJDhrWZgKA7G+OrK73 2WQcJ1keyMF6Bj0SqC2a6S4rbeAPKtNBvZnn0FigZchhi15zc3bqoD2kw3Xh0ENFBpj5 kqkjIWKnZg57TJYmZ/2kOKMsVWOCZHX3qBPHIeQ4yGNaW1G0oFPp23GUQzoBju8hDjXk l/qX+4O7B7s5KiAQMh4cixER5IYznoYqK/wtURsB8a0X186m8ox0AmBeElp4PUnAxK4m tNTjsYrY454J+/pL1015KDr3ca3KNb2icNdiqqG4W9v0RoLgDNRSQ1PzqNgPFNCjq95D cXPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=Fr43CPNAxaYFTPfYJrdJGszAUTRU+qSEGcx9D7xY41Y=; fh=VEycQv3NA+9g5kYeC1D4rAUOetkwyyNhygqN4ikf8w8=; b=CMoG+tOFsNDpB3EP8cl+67Y91G+BNVZnO97X8N+KNnsyan3fGf4B19mjpb78Aqh38S QQ0oWLmDGTSb2gkCtZsOL/sk3nGfzWI4iyi8NZkllpe05QQJ8byMmWw89w/wORzRR2UZ pUhNZ8RlQl0Ffs1EY3qWWP48VjuEGhMSAedU7uWth/beQuncRs/ypUkTofMBC8Qgg+46 JUvcXjlvulpmg+p3Dr0akPmiUynB3vZVhOime27oFIw5aBlTILesBmisEx8IRhxD4/VZ O/1S2gW+gby/N+8OQveRE5oCZc9zLSjto03r6Sz733OL2CWqW0JSAG3qTBlINOA8O7YG IB/g==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781637117; x=1782241917; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Fr43CPNAxaYFTPfYJrdJGszAUTRU+qSEGcx9D7xY41Y=; b=MBeLsMEkcVKiggkIg3ijSIWBmAbBO2cxHDr1ndXQ+pIMwhR7GEGow1/B8ACJuj37OF gr7SkA/WjVWNx668b78gj1PLIltlm/9FXl5X3Avm3yUZFLx4aVzyA5nKvzX4qHFlR8vg +V+1CkJn2CgtsdtBPV2I52V0+BI7FmjJx0N7GP49e813UU148jJzpfzpyeHIlHAcidXS H1/EUyrTEJai9DwRGOzapfoM+Mwtz9yAYRZaHDO0lpECbTr5DR5qeNZz/C04I1lrrQPk kWNj27dU8JGIisvY4DmQL0qkIj7YGqkox/XEt79LM5++TR3IIFLMCXydvD84d16CrF2s zihQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781637117; x=1782241917; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Fr43CPNAxaYFTPfYJrdJGszAUTRU+qSEGcx9D7xY41Y=; b=h6dWJat4264BGY4YVamJMk1A6fOUVc2exVzZcD1VDgt4afanmiNjeOvUMf/Jj0uNnU /Z4kPUX66ba5PmqebpSza/WmcKCr9Kza0U45CeQOn4KX/McsyqOuj6ShURGy7Kg58Qs0 ioMK31c+cZI3xCQ5LauLaUwA530DBKQriqZz+UcKn7dyyi7IJr+OApbZxQ1luc0flkYq NHdjg+/pp4pcNH7ye6qrT8gV1k8b8Fh7frkyclmHOYZmzBYuOLNksTwiV+We91PBScZh 3g2/K7fao+AXN7k9tjcXnZXC080YMU/Gepy0ZZbC48A7dX2BWxZn3Qm5hJVEfXrfZGOt 9UPQ== X-Forwarded-Encrypted: i=1; AFNElJ+bS046/7YOA4lv+Zd10jOURhma/bWEJqNT23O+WgVPz0CwBv9X9nSfLQdfC8oeCcxjTIvwFNxFF9pelW2L@postgresql.org X-Gm-Message-State: AOJu0Yy3r8UddtOP1lQnyaemh/0G4MVyq12KYm/7iJxOn0YNC8bU/4Vx HyqrcTE4F67FqrJNsAYsfojrC6nEq+Mf41gTAYUnKoyVE+ib+MKoh3jEckn7XCF0syJ4qcYXsx+ CKDSDy3fYf216OgsD+5yO5O77eE+ectM= X-Gm-Gg: Acq92OFhQYfsAKGfjirsvwkwmGgR1F+ZEaTPWu+QpV5tEFrPPu1r4sKlxaRYGPqlpGB gLbPk6KAW2Femb1/drbaZ4rox6kbhPseq/QgB4QXAld14G/wd+elnMn5TTfzvYDmkHGOJnQJRTs qzXo/Po2vm1w0P5h2PzDQjSn45ZqMNNGc8yJi3M25qc8Zgh7t1znvFBkhPh30KKi2Kocj/NKn2Y AXX0Mw8DAfkpsuFMjsL/8GNOLEVbxCoEPt7rvnBDGtJxyL8vKUiYL8tYRbZ4C+h16IP9Xz3tbP2 JiOc4yogs/RqsS3HwenY//ZDZbHIgJHHAVm7FdNPvTDxB16+6rDzXIG3JsrNaJcvHJe4EfElE9d fsrsmHWF+YsYOjHE0RA3GpOQf X-Received: by 2002:a05:7022:fc07:b0:137:ea00:3f49 with SMTP id a92af1059eb24-1398f6cb641mr120327c88.35.1781637117340; Tue, 16 Jun 2026 12:11:57 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Corey Huinker Date: Tue, 16 Jun 2026 15:11:45 -0400 X-Gm-Features: AVVi8CdxfdPPMJ8YZxkhjEo-ATdE5zWjaTtnC9-68gOAtPZ6XWs3On5d32o2H3c Message-ID: Subject: Re: use of SPI by postgresImportForeignStatistics To: Robert Haas Cc: Etsuro Fujita , "pgsql-hackers@postgresql.org" Content-Type: multipart/alternative; boundary="0000000000007f71e6065463b7f3" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000007f71e6065463b7f3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jun 16, 2026 at 2:08=E2=80=AFPM Corey Huinker wrote: > > On Tue, Jun 16, 2026 at 10:34=E2=80=AFAM Robert Haas > wrote: > >> On Tue, Jun 16, 2026 at 8:04=E2=80=AFAM Etsuro Fujita >> wrote: >> > I thought it would be a good idea to use >> > pg_restore_attribute_stats/pg_restore_relation_stats, because future >> > changes in attribute/relation stats would be absorbed by these >> > functions, which would lower the maintenance cost of this feature. >> >> I agree that we want to reuse code, but this isn't the right way to do >> it. For example, when we want to look up the OID of a relation from >> SQL, we can say 'whatever'::regclass::oid. But when we want to do the >> same thing from C, we don't construct a SELECT statement and execute >> it via SPI. Instead, we have functions like RangeVarGetRelidExtended() >> which provide access to the same underlying functionality more >> directly. >> >> Another example is converting strings to integers. The user calls >> int4in(), which then hands off the call to pg_strtoint32_safe(), which >> can also be called via pg_strtoint32(). Hence, C code should prefer to >> use pg_strtoint32(), while SQL will go through int4in(). Both >> ultimately reach the underlying pg_strtoint32_safe() function, but the >> interfaces are different, so that we can have it be suitable both for >> SQL access and for C access. >> >> This needs to work more like that. The underlying code that ingests >> and updates the stats should be shared, but the stuff that is specific >> to a FunctionCallInfo interface needs to be separated out so that we >> don't need to go through that when calling from C. >> >> > Back when pg_restore_attribute_stats and pg_restore_relation_stats were > being converted from positional to variadic functions, there was a patchs= et > or two (possibly un-posted, because I couldn't find it just now) where th= e > variadic functions re-marshalled the arguments into a call to a > fixed-parameter function. If that model were revived, we could have a mor= e > conventional DirectFunctonCall() interface. > > Is it possible that we never built a direct function call interface to a > variadic because we never needed one? Perhaps that time is now. > Obviously, even that wouldn't get us to the no-FunctionCallInfo-at-all goal, but it would get us out of the SPI situation. If we did have a non-fcinfo function API, that API would either have to pass char *params almost exclusively, or else each caller would have to do the translation or float-array strings to double[] and such, which would be a lot of work for the caller. Would you be ok with a function like attribute_statistics_update, but purely with cstring args? Obviously the callers would have to modify their calls each time a new stat param is added, but that is seemingly preferable for you than the current situation. --0000000000007f71e6065463b7f3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Tue, Jun 16,= 2026 at 2:08=E2=80=AFPM Corey Huinker <corey.huinker@gmail.com> wrote:

On Tue, Jun 16, 2026 at 10:34= =E2=80=AFAM Robert Haas <robertmhaas@gmail.com> wrote:
On Tue, Jun 16, 2026 at 8:04=E2=80=AFAM Et= suro Fujita <etsuro.fujita@gmail.com> wrote:
> I thought it would be a good idea to use
> pg_restore_attribute_stats/pg_restore_relation_stats, because future > changes in attribute/relation stats would be absorbed by these
> functions, which would lower the maintenance cost of this feature.

I agree that we want to reuse code, but this isn't the right way to do<= br> it. For example, when we want to look up the OID of a relation from
SQL, we can say 'whatever'::regclass::oid. But when we want to do t= he
same thing from C, we don't construct a SELECT statement and execute it via SPI. Instead, we have functions like RangeVarGetRelidExtended()
which provide access to the same underlying functionality more
directly.

Another example is converting strings to integers. The user calls
int4in(), which then hands off the call to pg_strtoint32_safe(), which
can also be called via pg_strtoint32(). Hence, C code should prefer to
use pg_strtoint32(), while SQL will go through int4in(). Both
ultimately reach the underlying pg_strtoint32_safe() function, but the
interfaces are different, so that we can have it be suitable both for
SQL access and for C access.

This needs to work more like that. The underlying code that ingests
and updates the stats should be shared, but the stuff that is specific
to a FunctionCallInfo interface needs to be separated out so that we
don't need to go through that when calling from C.


Back when pg_restore_attribute_st= ats and pg_restore_relation_stats=20 were being converted from positional to variadic functions, there was a=20 patchset or two (possibly un-posted, because I couldn't find it just=20 now) where the variadic functions re-marshalled the arguments=20 into a call to a fixed-parameter function. If that model were revived, we c= ould have a more conventional DirectFunctonCall() interface.

=
Is it possible that we never built a direct function call interf= ace to a variadic because we never needed one? Perhaps that time is now.

Obviously, even that = wouldn't get us to the no-FunctionCallInfo-at-all goal, but it would ge= t us out of the SPI situation. If we did have a non-fcinfo function API, th= at API would either have to pass char *params almost exclusively, or else e= ach caller would have to do the translation or float-array strings to doubl= e[] and such, which would be a lot of work for the caller.

Would you be ok with a function like attribute_statistics_update, but pur= ely with cstring args? Obviously the callers would have to modify their cal= ls each time a new stat param is added, but that is seemingly preferable fo= r you than the current situation.
--0000000000007f71e6065463b7f3--