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 1wZcc8-001AsH-2I for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jun 2026 22:50:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wZcc7-003C5T-1U for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jun 2026 22:50:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wZcc7-003C5L-09 for pgsql-hackers@lists.postgresql.org; Tue, 16 Jun 2026 22:50:35 +0000 Received: from mail-dl1-x1234.google.com ([2607:f8b0:4864:20::1234]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wZcc5-00000000iJY-2j2a for pgsql-hackers@postgresql.org; Tue, 16 Jun 2026 22:50:34 +0000 Received: by mail-dl1-x1234.google.com with SMTP id a92af1059eb24-1384ebe7a10so250750c88.1 for ; Tue, 16 Jun 2026 15:50:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1781650232; cv=none; d=google.com; s=arc-20240605; b=F8pkMyRyBIFpZcRj2pPkNxCs5sTV8jLGVRdF8Em/CNaSuFjhK4EK4BxTwkxCINqWTe fsNty3y0LcdkP4U+Uoz6yKKdVJT5XhHTABfmbXUwJREkxJVB+406rKoNskNZpqRtl7HE YGWhyQ/AFd+nwmhWCRZXzVoHDOKQjeDnuiGvclVWUiD31LnnPE2XkJ+CNbaB/9Wa7uaU afRG43UFsfZiPKXhktZkYTAhe3PplmvodNdWHA/77ErBYxyzv4tj0rX/86vXNxKmaoH0 3YbrWKlXDfbT9zsa787R5p+gHKRCj/heAdQsD0MGW6ZiUbFpQtW/YZQ1vmLFW8vubR4/ 9ydQ== 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=DyFcRWT1ijqfxVB4v7cJBlxUszgyqadleG0eQGINLrI=; fh=HauAhPHNXdbSmmFEydxCpH1F5qUHQqQ0I2E+X+WjoO8=; b=fia6K9i1XKxzvyVmLiMX+crsCQnwlKVKoaMzbTP1hAnmQPohRymnJuAZIbPpJgFHKn iSnjB8kVhCNgoSlLtrgsCrgNIm4ahF2ubnSpPG7ePSgrk4gaLVotDkvOb8rQWWSwKiTC 3ql0w8qgRQzsv5GH1bPfgMEPl0OzLkdVfpC27E0m1fEWU3R12GvmMHkzp60hZEUUmjI9 UX4q8FJw+EA+0H1XGowUjDHy5CaHNLfE5/Z5VONfYKqi6j5jGF4CWQHaQeniZAHZPiC2 T9lM0kMmu9ryxbIdCy5/Si3okFAMYIEJGaNDrybE1pjSQQ4Eyn1rA14OBKQQ6UPK+rKw eDkA==; 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=1781650232; x=1782255032; 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=DyFcRWT1ijqfxVB4v7cJBlxUszgyqadleG0eQGINLrI=; b=i8nL+w/yuGourx73DSj1UVMr8La64Us5afEjXhB0vMxuz/sPJA5W/7ycYj3mEMgmU5 suG8ZEhBFV/ohtFox13b06DLqmrhyXszTgrmGY99nVW3hNjQ9DAONRjUeZLgS+Cg3IB0 dK1iJE+Pg/au/lUVbdDftEqgK/mfzq40nOHDnrJJAsGBUEpc2nNYNGNyhXDtQH8wciBB pqu3CQUQna5z89y2quDZro0NGyzUFBBiOry5an++shBQc05duzjx8ZjgEldmHOjqFTyb YYmuD19nyiW45v9l7HzF1+ih/qWV2nX3fxU5QW+cOyzn5m4IJS+uOaS2mrzAHun7LQzi b0NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781650232; x=1782255032; 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=DyFcRWT1ijqfxVB4v7cJBlxUszgyqadleG0eQGINLrI=; b=JZQO5An1VBJ0BgYaH0AcD93vU+o8f3aKdJur6j114eh2fdTsSqEp8SWKlGcpwHO836 Eaki9VtDW5Y45ZHyw7FxVS8MRXCzhi8WiwaUqvJ0rGBxH760Tp+YBxFjk60ht9UsY8MC 6npeZBqEfKphlgitvTSNkBkjwxeEkMTjS+cc9L8euG9x6vXxUVU4ZliOyxEv6KUOtk4F HWIeNxzmDar9yyo7On5j3PMhz9rYk/2fBMRuuC2oAx1q4K+ChTNDtGqNVTQBel48lpNj QHksvThFkaZAq8HT4rwrfk36PnPf+Ci/VD2PlccZ0YpXEWoM3GAQzxzO/arGI0CjyDFW 4X5A== X-Forwarded-Encrypted: i=1; AFNElJ/FAH40s0ZVr8bHUx9Dj6/Gc6eM01k45lKgrKU6TBX/7c5hVd0IURDlHzdjhg4Nwup50yoIoupaqZsp9TGH@postgresql.org X-Gm-Message-State: AOJu0Yxps8uAMpjmQV1AdqkxK9CYAX3q+f8MF3FW7xPgUNy2Ok6B1sRB OB9FoJNoRarXhe/A6ai8HLKClUb/gZwXRmhJ6z86VKXuuY8XhT2ANxxi9NAYhAoUownY1AgIZFe +Up7KQlqHgvja/eZLPdpGzHeWxowyPMA= X-Gm-Gg: Acq92OHe+oZMAFSjuE41yML8Hj0KAjskpboKvg8b0pbPVGPN8TIthQAN5X+JDLj1QFH kIi4lowbBm5VjeFajYhzyaNoHkljXC92ynulgyDOp8ArcGSqXo6Z6V1/0MhADb34zesPZq9p71H uM2g0ymLppZ7qErFMsTEBE0v4clem9KJipKtAtyf7/pvMcEdV+hRUisFassd0hcpxwYXQKbNZRF xpXp8aipVqZpqpj6oj4iWDjwNbfjCBibTVBuzWjLFIABIvsYXqAW44sAxJwbI8+fDw+jFPwvAXI WNJpKH6LGrB7vVFnV2SGxdbRI+RMQD84iweFZFfWcR6hq7Re7BxN9l6hF61eybBChgRnJVdYwau oYVVcnFKOJK3q4+8NULmD3G+2 X-Received: by 2002:a05:7022:3d12:b0:138:30b1:4c09 with SMTP id a92af1059eb24-1398f676146mr478366c88.10.1781650232216; Tue, 16 Jun 2026 15:50:32 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Corey Huinker Date: Tue, 16 Jun 2026 18:50:20 -0400 X-Gm-Features: AVVi8Ce29Yyybuqxt4UOrVrs0ovs7QKl8CK4CHG-eiLlYA320ArqPumXz8QAurM Message-ID: Subject: Re: use of SPI by postgresImportForeignStatistics To: Robert Haas Cc: Etsuro Fujita , "pgsql-hackers@postgresql.org" Content-Type: multipart/alternative; boundary="0000000000003492c0065466c58f" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000003492c0065466c58f Content-Type: text/plain; charset="UTF-8" > > > > > 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. > > I feel pretty strongly that we want a way to identify the relation by > OID rather than by schema and name. Previous versions of pg_set_attribute_stats() were like that, but it went away as the use-cases folded into pg_restore_attribute_stats(). So it's do-able, but will make sharing code with the existing function harder in the near term. We may have to settle for something that takes the oid, but then plugs into the existing functions until such time as we can refactor the existing callers. > I'm not sure whether attributes > should be identified by name or by number in this context. Apart from > those things, if passing strings and leaving it up to the called > function to interpret them makes most sense, that's OK with me. > Identifying attributes by attnum is mostly for index expressions, so attname would be the preference here. > I agree with you that getting rid of SPI is a much higher priority > than getting rid of the FunctionCallInfo stuff altogether. I could > live with DirectFunctionCall if we don't have a better option. > Ok, good to know that I have that as a fallback position. I think the right first step is to create the functions import_relation_stats() and import_attribute_stats() which take the oid of the destination relation and the rest of the parameters are const char pointers, which is the ideal case for a bunch of values being fetched from PQgetValue(). Those functions will for now just make the call to attribute_statistics_update() / relation_statistics_update(), but at least it will be localized inside relation_stats.c and attribute_stats.c where we can make internal refactors without disturbing anyone else. Now, we *could* make these 2 new functions take the oid/oid+attname followed by a variadic array of keyname+value string pairs like the existing pg_restore_*_stats() functions, so the functions call signature would be somewhat future-proofed. Let me know if that violates your vision of what this should be. > I'm a > bit suspicious that this will lead to code bloat in postgres_fdw or > elsewhere, but maybe not. > postgres_fdw will get slimmer for not having SPI in it. relation_stats.c and attribute_stats.c will have some temporary bloat until things can be refactored. --0000000000003492c0065466c58f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
>
> 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.

I feel pretty strongly that we want a way to identify the relation by
OID rather than by schema and name.

Previou= s versions of pg_set_attribute_stats() were like that, but it went away as = the use-cases folded into pg_restore_attribute_stats(). So it's do-able= , but will make sharing code with the existing function harder in the near = term. We may have to settle for something that takes the oid, but then plug= s into the existing functions until such time as we can refactor the existi= ng callers.
=C2=A0
I'm not sure whether attributes
should be identified by name or by number in this context. Apart from
those things, if passing strings and leaving it up to the called
function to interpret them makes most sense, that's OK with me.

Identifying attributes by attnum is mostly for= index expressions, so attname would be the preference here.
=C2=A0
I agree with you that getting rid of SPI is a much higher priority
than getting rid of the FunctionCallInfo stuff altogether. I could
live with DirectFunctionCall if we don't have a better option.

Ok, good to know that I have that as a fallback= position.

I think the right first step is to create the = functions import_relation_stats() and import_attribute_stats() which take t= he oid of the destination relation and the rest of the parameters are const= char pointers, which is the ideal case for a bunch of values being fetched= from PQgetValue(). Those functions will for now just make the call to attr= ibute_statistics_update() / relation_statistics_update(), but at least it w= ill be localized inside relation_stats.c and attribute_stats.c where we can= make internal refactors without disturbing anyone else.

= Now, we *could* make these 2 new functions take the oid/oid+attname followe= d by a variadic array of keyname+value string pairs like the existing pg_re= store_*_stats() functions, so the functions call signature would be somewha= t future-proofed. Let me know if that violates your vision of what this sho= uld be.
=C2=A0
=C2=A0I'm a
bit suspicious that this will lead to code bloat in postgres_fdw or
elsewhere, but maybe not.

postgres_fdw = will get slimmer for not having SPI in it.=C2=A0relation_stats.c and attrib= ute_stats.c will have some temporary bloat until things can be refactored.<= /div>
--0000000000003492c0065466c58f--