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 1x1uHJ-005U5D-2d for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Sep 2026 23:22:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x1uHH-00EW7Z-35 for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Sep 2026 23:21:59 +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 1x1uHH-00EW7R-1y for pgsql-hackers@lists.postgresql.org; Wed, 02 Sep 2026 23:21:59 +0000 Received: from fhigh-b4-smtp.messagingengine.com ([202.12.124.155]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x1uHF-00000002crT-0rUW for pgsql-hackers@postgresql.org; Wed, 02 Sep 2026 23:21:59 +0000 Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.stl.internal (Postfix) with ESMTP id 273AA7A0015; Wed, 2 Sep 2026 19:21:55 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Wed, 02 Sep 2026 19:21:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1788391315; x=1788477715; bh=SIq5iLcSCI 5ehQrMd014/8tvO7G80TaYPlRIvLQYoyw=; b=YH0V420QQM+dk8b8jdgLtCs0EA /yCeNhCLUPH1BIbx31ZC9dM3ju4hjYXt9XXfo/L8/JTJd0uV9t8kMxd8R6Xrkxv3 wL474Hqh37TRfQCcSrHXS+itibQcISBmpVt7N7V7AsJVnf2MPdMEWbKCvu9h/yZH iIO7O/Uj/b/DvLFmhJDkDYIfuylVvbeYEov8gHSsOYrBaA4b7WgP3IBYmugvHx6I Vtyb68Lr6kYhewLrfvFaZVnYtynpvx3rgotNRSwhRPUqOVM3Lie+Bi9bkHKykRBJ mjCMxp1ND5ymzPvyuPjKe6A+vwCtMau7F1jUGeHiRl3lJ5f/8Sy+XRNPmPYw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1788391315; x=1788477715; bh=SIq5iLcSCI5ehQrMd014/8tvO7G80TaYPlR IvLQYoyw=; b=hQcL6NF/LI4U2ogr05kb+t29SDGWRmqmhp+g5q7waJH0KmpS51V SWcaDmDNT00UTyweH8gzB/gxz7bEmpHWSUwHnbBppc5aGmtxzKJiQ5SFea+akXUq VZ+vyuODCQMpCBuDxQE6Yf9uEefLRojlVP8zayLIsjz6lyie0bIxICLUAEdeDzmw sRUf+0QCQyt7KTc3pZSRCN7LAHJyL62Bbjw3HyXU7wu5PRqWssugEkOEEjC62Iks vQN9MwmQ/X3bzDJE9BzfvVvBrJPW9rMvL72mIO6w7cO8BKcrElnGSg/S2+FJ0XBX VklNU2v6OfZnWlBY3twKzD9aaoIffSGKYew== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTF9p/aUnxjn+Y09fJ4xalis94/9zEPldYUsXM5YWdzXP//BeUdH3ebsIWKT1RR3Ex PQj0QjN84hfJdstKc/l5d7PfuTypQ9qcQL5YScF/nbu8vKoMw9SxW02D/rVVGaa1S8gQt/ EAR1eduAYs1PqMJcwetpyA7WrotPNzPoNMO0qqpiBrvHPxnIsKOCcK9Vf5Q4LszEyWMNvI qVbhTY6+BEbhuppoVDa6GqTKOkP4WeWQCjDwUsUIengZBeSErFtGC9CwG5oJ8Bz7ybWih+ /MQ+cksSy9RZq/6FsQ9z4XWt99r0G3108ADxMtB0ckbRldVF02YtmUrx4qG7EGaG6Es7H8 k+HsY5vg384XU50e2bznlGa9phCCq12BnpCEofKle/cimHfFEYxB1PR8VL5ooHKyeIv0v4 NtefPFaz07ucTE7nxzJlasE2Eradby7GayIuOhQt45pl+Ac5zfX4RTzTpzQDbBR3tlIQto QoXTdRP85WN3lCrghS3W9dNrkRZyfsj44I2/ut1Dxlqr723oQnEoVxG5s6QcnMBsNOSD83 VcUlfPcop7wx/Om+4sPTwV3m7z4VJnpmN8u54saaUBsB3SRbCQzkF52A4XqIccpzVbnIfo 2cXcVeNEuLoMiShxTfPm5CbxbmcgQH5jRxBovrU0fuDYVCVBO/5JM8/t5M6w X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 2 Sep 2026 19:21:53 -0400 (EDT) Date: Thu, 3 Sep 2026 08:21:49 +0900 From: Michael Paquier To: Corey Huinker Cc: Etsuro Fujita , pgsql-hackers@postgresql.org Subject: Re: Remove fcinfo from statistics update internal functions Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="7+PvVW0e2Vm7hxKD" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --7+PvVW0e2Vm7hxKD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Sep 02, 2026 at 01:21:25PM -0400, Corey Huinker wrote: >> Also, we have exported import_attribute_statistics() in v19, so we >> should avoid changing its signature. So I think the second patch >> should be reverted at least. Sorry, but this isn't that trivial a >> change, so I think you should have taken more time (at least a few >> days) for others to look at it. >> >=20 > I remembered this hours after sending my message, and I agree with the > concern. Sorry about that. I was just focusing on that yesterday and the cleanup was feeling worth doing, and well... It still does. >>> With that, we should be able to bypass the positional issues, as well >>> as the fact that some of the parameters are not used, while cleaning >>> up the FDW-side import functions and all their arguments. The point >>> is where to make the cut due to the pairing of the arguments from the >>> fcinfos in the restore functions, but that's doable. >> >> My way of thinking is the exact opposite of yours (and Corey's): I >> think it's better to handle both restore and FDW cases in a unified >> way, rather than complicating the code for the latter case, which also >> makes the version diff large and thus makes back-patching hard. >> >=20 > I'm actually going to carve out a third way of thinking here. I think we > should settle on the FDW API now, and we can fix the internals in v20. I still think that using a set of two structures to pass all the information is the cleanest way forward, for the following reasons: - Previous patch 0001 tried to reuse the same structures as the restore APIs, with some of the parameters getting unused. This creates a weird design layer, because the import code begins to rely on portions it does not care about. - The dependencies of the StatsInfo structures used by the restore functions become more integrated with the import code, but I doubt we want that: the import code cares only about the values, knowing already about OIDs of the objects to manipulate in the catalogs. - We finish with APIs that are weaker to argument reordering. Values in structures are self-documented. - A suspicion: long-term maintainability cost. > The existing v19 FDW has an unattractive number of parameters, but that > becomes a strength in situations where new stat types are added: a missing > parameter is always a compile error, whereas uninitialized struct values > are not, and undersized arrays passed into a structure are similarly > dangerous. This strength is more important here because the programmer > likely using that API is an extension writer who will likely compiling th= at > extension across multiple pg-versions, and wouldn't likely notice that an > array got one element longer from v22 to v23, or this struct had a member > added from v21 to v22. So I would rank them as mass-of-ugly-parameters > > pointer to big struct > array. `They will notice a compile error, though, > and that avoids a lot of POLA-violations for our consumers. We are never going to add a new stats value in a import APIs on a stable branch, as it touches the shape of the catalogs, but this kind of code style itches because it is weak to the ordering of the data given in input, and it still forces anybody who uses this code to set every field: /* Try to import the statistics. */ if (!import_attribute_statistics(relation, attnum, false, &args[0], &args[1], &args[2], &args[3], &args[4], &args[5], &args[6], &args[7], &args[8], &args[9], &args[10], &args[11], &args[12], &args[13])) Honestly, that's not a pattern I have seen a lot in the code base; we tend to use structure-based approaches to pass down data rather than a lot of args, because C makes this kind of code written easier to parse and less opaque by assigning values to each member of the structure. One example, the [auto]vacuum code for its state data and its options passed across various stacks. > Internally, the calculus is different, and the pointers to a struct feel > cleaner and more self documenting, and also serves to alleviate my > discomfort over using regular strings over constants or defines, as the > string being used is always the struct member name in quotes. The discomfort I still feel on HEAD regarding the fact that isnull would be set to false for each NullableArray, meaning that some could would attempt to set a value even if nothing is safe, is something that is IMO a defect of the original v18 stats code: we have no protection against that at all. Using the fake FunctionCallInfos or even the 0001 patch does not offer this kind of protection either in the restore code, which is a problem. I kind of agree that this is kind of impossible to miss but that still makes me very uneasy. In the import code, we rely on a ABI breakage to let extension developers know, why not but it does not handle the isnull=3Dtrue case cleanly either. So, isnull=3Dtrue is not something that we can enforce using a C initializer of the type {0}. However, it is something that we can enforce with an initializer macro, as in the lines of (same for atts and rels) in statistics.h:=20 #define RELATION_STATS_VALUES_NULL \ { \ .version =3D {(Datum) 0, true}, \ .relpages =3D {(Datum) 0, true}, \ [...] } And then use this initializer for the defined structures, for both the restore *and* the import code. At this point, it would be impossible to miss that the initialization macros need to be updated when adding a new field, and extensions can use that to deal with their own choices. That also takes care of enforcing a cleaner default for the restore code, something we do not do now, even if we don't add stats fields very often (the last instance was around v11, isn't it?). It is true that it does not make extension developers consider about the new fields, but I would prime on the arguments that a safer default for the catalogs is saner argument, and put the trust on the developers if they begin to use the import API to push data to the catalogs. > The internal bit can wait for v20, as was always the plan. If I had thoug= ht > it wasn't the plan, I would have kept up the work on this thru July. The > FDW API, however, I think we need to decide now. I'd be ok with going to > the struct pointers in the FDW API, but we're creating a hassle for > ourselves if we decide to do that down the road. What matters the most to me is the long-term maintenance of both code structures, and the more I think about it, the more the structures lead to a so-much-cleaner result. That would be even better with two initializer macros for each structure that extensions can just reuse to force isnull=3Dtrue for each element, though. This enforces a safer catalog insert policy for the import *and* the restore code. -- Michael --7+PvVW0e2Vm7hxKD Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmqYr40ACgkQnvQgOdby QH0Xgw//WwqgbfAV46RNnzKAik5eOKexSKQMfd0nAu8Fxhc7KGgr2MUGMXauxZkS 0CCKZUwhXO0vQyAKn/xAlL1IuztCfetN4Rk+wzUuUuEX3pNAyI/lJoK9yjFEQe9J 0k7JDgYrrKY9Pd7pWydYo/up6M64275sWtPquWTXZP2RI+zylaylNq0FttEDgC6u Z7NyhHZGDUj7sNzWFp9bgQ0SLLu06xSjwGtCEKwYN+E0ep1ld+jFw+2aP92SJ1bz LM+g2ch0jpLds9E8KMGCTO6ZQeKE89bQZwh3YweHU8vcKz3dxScMMw453k/89IoU CxGBbkE3J/mhFXSXzNgg5fCIyUbfFMZS60fq78VnfNDYAW4aOZ5nF4A5Z4RAUbqn FCxUTUks0LtqLLi6vCjzgZXjCoMMAETz7huw8HSTmYVwso1JAjFvz3hl3byxOthz IJM/Ga1DREHH5A4yn0V8WJJ4+2zcq3dKL6mKizQwIDIKI9Uumb1S133HW6dGHn4i B0aZm1aBn1B1pDyDN2sQTP/b/xa10DQTVKL3f5Vy0B68VP7XtoIS66oJ78ZTPrPe MxTgAMrEAhLgubnA9pdnsY2JPY2XgapXI4XigqNW8p6yYs99Rs1KEqS685Aa3Ekm 0myf9Rn5pifSYGYE8Y1lSzpHtCYiLJKO6xVweIr9XnSttRHvUKg= =xT79 -----END PGP SIGNATURE----- --7+PvVW0e2Vm7hxKD--