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 1wZYDl-00183W-2p for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jun 2026 18:09:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wZYDk-00277r-1q for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jun 2026 18:09:08 +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 1wZYDk-00277i-0l for pgsql-hackers@lists.postgresql.org; Tue, 16 Jun 2026 18:09:08 +0000 Received: from mail-dl1-x1234.google.com ([2607:f8b0:4864:20::1234]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wZYDh-00000000m9Y-2u3r for pgsql-hackers@postgresql.org; Tue, 16 Jun 2026 18:09:07 +0000 Received: by mail-dl1-x1234.google.com with SMTP id a92af1059eb24-13981833e13so2217870c88.1 for ; Tue, 16 Jun 2026 11:09:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1781633343; cv=none; d=google.com; s=arc-20240605; b=hHxrn6i3Q1HvC+5ngY44rSEqPPQd6pPhw1r+k8aWPJhUyYMWP9wgtAf8+rDeW6rG9b I2gvUwmK5P51HVGGeBKrvL/AB9ev4bNA8L/a+dlsqEl2a5vaUHQPY9cdvftrsbj7h8sS 3S8JSxZyPY123ngsUnMhSBoNO/sdzrHtzUOVJ1ix9NM3jrrKJttaXhOVuf6auGbAI11X SQxUU3ZMCxkPJj6yiFNzqNRE//4Pz5XvdfRISuOi1WTBFWTSAH4QF690ft1GmBTuo7Tu 4AqxPx7Krc8C4tiChIJRuFdA41Qu6LY/XkKoYPxnc8iE8BbPQmB3yAaDUO84t6sua+7g FWvw== 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=01cXK9vGABegJaOLFf2lfacRPa43lQ0G5csa97ku/TA=; fh=FdP9Z6TMmSWAf+8mcAO4/fMMLI30wXD8ENV0ken50L0=; b=haytHZBNiRAoMm0dwEHJ3xWnFqHGl4TxsBCPbJo0Gekh5Frh8qdB9bcMonc38AqdVH 3UrKCiAVRZQXreRhYu+/fKG1Q+eHKTUoXAfv24b3brczoFmss5aSevehRTIk+ILZ8iFb 5Fa0sdZ5KxBwkYnrOflwwwxDlJ0UOrd6G2bhMl4gKH4e4yXViiTUDTCeuMU5Z8QZyask OR01Wecvbk3GRqNUPBnqoAk+jnpd4pNs2DFBD20/afWI/aMJl5VddbQaJqOUHNAN7rK5 k84kNJI6fmQnyzyyPgg5U8kLnOcvFrp+N2Y07ibX9ZxyXcqRcGpvqXsq4yonrnOXyByP eZHQ==; 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=1781633343; x=1782238143; 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=01cXK9vGABegJaOLFf2lfacRPa43lQ0G5csa97ku/TA=; b=RH0Lrc5L2IqM1729uorw0z2dipPnItCXzJicKaylATzdVjepDRx0ylTnpmKWJwwiYt y4HQ4Eb0P9ajCsthDddr/tD+Ccxq68thmDqgC1y7Qp28GJqu9FR+4Gq29rzDA9K/llSk SiUg2u1IMyUP23KjmA92CYsVIHWLkIWJnDIWrALY3ib/IwzMfHzFT4K82bbW4WpM088U oxXa8DKitbShMV0GTa7QBoiQwpZYadTHo/UHqsirb56le5Vg5fKf0Su14UZl6XbUijxn /wGHoxaDtDKrUt+ngy06VXnjndaGHAeYfNf1gYs8N178begoZFfRbjr4qUN25sXe8SFZ TdbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781633343; x=1782238143; 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=01cXK9vGABegJaOLFf2lfacRPa43lQ0G5csa97ku/TA=; b=aEcQX6znZs3dtKNKEO1yelBLLKVfPpOpLxQrBRdwBX/Iak+Fq9woopfWwIQ24y1H39 /tI53X+b1C4ZVhk06ygfowuFMxfzqANGIhz02SIZP9dyZT3desb7SriocUnJdbnTXeIV ngvTY7LbEjBOE4DxSsHkQnlgh5CU5ImdqPsvbylSSjCXIrYotaYK2K2ThFEDxg1HWrWF jaMg4WdqIbQw1kbK8ddT+rgvGMBYuetUf693aRGXJu/ev+/us9O4//36pznFkLyEXrv1 vBt/KbYOc5dMmYK1ZkUnCM90YR6qXjZleEKr8tya8VCh8e/HW0Aeb9/0VMJu9H/OGaJH 8H6g== X-Forwarded-Encrypted: i=1; AFNElJ8ewo1sI/Q0zUD7MxGCgo5+O1yuQwxxAVWnWQG1aMM5Vdb1kykzhOzU5v2V8hUaokuHOYDpncCVrLflfdVR@postgresql.org X-Gm-Message-State: AOJu0YyCv4INPMGmzyKF64pIy2VVkXM4QxDfInmBFv75FvJ7PwKQLptj RVVxO3foUKPNsPJa0pm36niQQYhZ0Bbb9XxHBB7jtg32Lns2ufNAdEALdZVuQypwXhag1zjIaSE u+aIttbmLiG0DZ63Ha0PgVGhB2smfMfQ= X-Gm-Gg: Acq92OEG1+m5qc5UrqWWzy+QZASbpNiz1dYtH4r6LVDXlnh9teIUoxhyK3935nRB+Jn x6Z85rDABv9JJC/O0R+pWGbdsCBThxI7St4UtcNVurhAijK8JSLnufSNkQD9p2QJc6v8E4xW1yj cmkIS4sMvDTOsyWhd+yPrwUkC0g/wBV+Xse2eLV9tLS9hnem3Vd6a3sK0kVEzyq0pPQsfz8pxOg Xj463HbUI5YXScycwR38ToNebnxvwlZ5Htkzul2Lu4E4Vg6hpU5R6fmNcQt9b1hzGorZ1ghilnO LMoIPa+B8SSLBmsrxhZbvshOLxScHzY0nimLwOlUiNFw4gcNuyKzigYzLPu8cGRmnOlWSkGy8AK iNrN0Fq382Qk2giOx8dUFY+jG X-Received: by 2002:a05:7022:23a0:b0:132:ac76:9772 with SMTP id a92af1059eb24-1398f6caf0amr19878c88.34.1781633343375; Tue, 16 Jun 2026 11:09:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Corey Huinker Date: Tue, 16 Jun 2026 14:08:51 -0400 X-Gm-Features: AVVi8CfpttDXBjg9bNqq9JdLGJOVyVS2ZZ9xUyTnITVVz7JkmJnAHcjxEk5gwCk Message-ID: Subject: Re: use of SPI by postgresImportForeignStatistics To: Robert Haas Cc: Etsuro Fujita , "pgsql-hackers@postgresql.org" Content-Type: multipart/alternative; boundary="0000000000008d5253065462d652" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000008d5253065462d652 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 patchset or two (possibly un-posted, because I couldn't find it just now) where the variadic functions re-marshalled the arguments into a call to a fixed-parameter function. If that model were revived, we could have a more 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. --0000000000008d5253065462d652 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Tue, Jun 16, 2026 at 10:34=E2=80=AFAM R= obert Haas <robertmhaas@gmail.c= om> wrote:
etsuro.fujita@gmail.com&g= t; 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.
--0000000000008d5253065462d652--