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 1waYMa-001swy-0N for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jun 2026 12:30:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1waYMY-00G4b1-0r for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jun 2026 12:30:22 +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 1waYMX-00G4at-3D for pgsql-hackers@lists.postgresql.org; Fri, 19 Jun 2026 12:30:22 +0000 Received: from mail-dy1-x132d.google.com ([2607:f8b0:4864:20::132d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1waYMW-00000001GaL-0IXA for pgsql-hackers@postgresql.org; Fri, 19 Jun 2026 12:30:21 +0000 Received: by mail-dy1-x132d.google.com with SMTP id 5a478bee46e88-30bf854d5feso3313301eec.0 for ; Fri, 19 Jun 2026 05:30:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1781872217; cv=none; d=google.com; s=arc-20240605; b=JW5217GNXDAVfK+XbDic3YOYJrlGqcwTL7aI4Pdyczsu80uOt1wKwyPCBFnGIEd2KB QsIrdgcnFHf+Ei8gu/ysi91ONcTDZ3TImV4hgVVd9BSzAs8Xy3xIwLODVN8GtTG0tuoH OQPVpDAb2Yt52mjtv0v18dNAdX0ANB1FZxQC/GJUwUwsQVJ6psw7tsaCPZBjCOlvGb1W 6LGk1lpfvhtIxWfT7vGTKKTHelRyWHlSsPpjZ7AG0ytaVtVcxWvBxi8YMnJf8HtiKLlO 0OR8RG9OoEb1uUyh2eQftrMwIxvCbjG/pepS/ah6FAnnPOOrGH26WBugOEAp62zYIuEL j7rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=KDXPHu5DjDFl9VPRILwGzZ+kcu/lTVLJ84AJ7q6/fGE=; fh=BHlNW/0ffhnXBctVChsH/rQDTxh0dnadFNqs6vLMjZw=; b=NkgNY/0uBVi0tpKSROUu3LrmThYPV5gRiR8G/FDcnuLumzuw7SWfX4vo3Uza7R/Uob dAg85TcvX/1lnOHlKhHIK5ooxIUKn0ikzT78fCZDIULlx3H/o1UIVV015cfHQE3qabqU SmT6PDkTVJ+8HMiKR0556GpzEgobkriYLxazISSkql0gyqr3nKGCgsCet9IWh0VACwn5 5eMAnjHE+1ZFzXi4wvUqkPM/BYhNAVT83+IyT8kvgI2b4NzIE/Dp6wreDisb/MgTuvk6 Izg18tTwEGxmV+svWWllkdeuCuhZ2pmCmSzALOatqlxeWFCpwh3H6ZIOBZn1hKEVZ/1K 2OBQ==; 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=1781872217; x=1782477017; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=KDXPHu5DjDFl9VPRILwGzZ+kcu/lTVLJ84AJ7q6/fGE=; b=RILDnHZqBeb+08VaAmVfbibRtHWzECfOT21pJQPXqeREoTOZ2upDcdzBpWUVaCx4ah lTbppoO6GbVzdrvse0DeVndQWnXQgVglG06ueE+TFjUD1/pHRgxKNZaxZ7MN9EHWx2Qp bqfBMK2I/QURtx2518iaU3TXahmo6Ghg6AKzvy7TvDvDebkh1H4cOvTw7U6H1C1jVAzD uJvSvfMLKES7gbKXdJdnMAuenXU48ZW38u6TxWme9QiX+ZiseK1SPVya5LSZuL9iJvqp 5xco99NZnVJE/SbxYTUV0FBPqFdEZWTp68orh0GPD/OvnTbzYBOLRg77q0j7RuVO111I 3BRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781872217; x=1782477017; h=content-transfer-encoding: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=KDXPHu5DjDFl9VPRILwGzZ+kcu/lTVLJ84AJ7q6/fGE=; b=HOLKLyl8kTQwRCxKtyYcSI4XfSmsTlp86kQihZvgIPBRQBxj5THv1vLQzb5RuKPOve HApG54VMgQgsc3CdREIusCbtseN84NG2I7gzSbHH0Jr+HVUqivcOMYm31pJuHudwSMQd 1FPFWEjaKl7WeOx+VkxuC84iXiGb9v+k07fNK7vUPyDDaT2kPGaBB8G5W78IebncGWXk JebCUPel7yZU/zu5pTAIclJ9bmBWiQqZvdHvHdDbOy5KrV6zbbI/EZ/XVd6ufKpg75mk E3sclKjEB567bfL51j3eMivoFQSMYO1dK2OrpisiQzjH0Qi4KJVnt6PfKnMGTXjhn4vr A2iQ== X-Forwarded-Encrypted: i=1; AFNElJ/hI4SXCDJtXIcKwAT79GFoOVbRJfmKVWzQxvLn/HVso7dI3kq1bzxcZc358LDfG1hyjsHQjAMVhyVXjYgE@postgresql.org X-Gm-Message-State: AOJu0YxGH4Y86B+kzpycKfUg9aC+sL7L0Fqrn+R8eC0eEstMfBv8sXBd w700UbG3Wyh+m4surN1AZZfV2hPxQNDOmPBGxAc1kuUNx8x4yZrXYHp+InagbNDpNP0wWUmlIXS iXBsB/STuDklvFwCsXsBDgAV75LtZQ2Q= X-Gm-Gg: AfdE7cntoO+FX2PkSg17Ms7wIB82m4XHbndu6w36RxrowuozcgW4fdMs1BqxUylr2ct uu35d/R+ma0IvsxlM/dYyuRD6XWTZZEfk3CsSxzQuYc6qvqAmdVjSmvuYeFUFUbeizjlccPAcbF hYbbC7ieACFsjSsZANquxdmWoXKbEEuKVPyl4XPepHZGs/MKkupmoQ0il7sbDmUdrmIaQbqAr4R CO77p/8YeykGjS59GJn64g1zl0wfltOFjwUl5GTPWZpVUrWKjwg6K3zjrGc8S0p6mu+RZm8ulrb cP8yq2kdlHHRAwQDLqtStNJwME2kBiogTaQdUWWb7Fo6fRQiqQQMTI7jyVpwu3ua866vUUShhwo 74QrhYBtKyivM3sZufsEMyXqxvtrwOLTliWaRI+2c X-Received: by 2002:a05:7300:a987:b0:30b:c40f:de0c with SMTP id 5a478bee46e88-30c0701d4bcmr2159373eec.10.1781872217412; Fri, 19 Jun 2026 05:30:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Etsuro Fujita Date: Fri, 19 Jun 2026 21:30:02 +0900 X-Gm-Features: AVVi8CetFuUPSSEpV8_dtIUESlSiDg4jZTb1WdiRJLyjn_hwj21c4MEFLUHBXfo Message-ID: Subject: Re: use of SPI by postgresImportForeignStatistics To: Corey Huinker Cc: Robert Haas , "pgsql-hackers@postgresql.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Jun 19, 2026 at 6:23=E2=80=AFAM Corey Huinker wrote: > Attached are two patches to remove SPI from the postgres_fdw.c, replaced = by local C functions. The division into two patches is entirely for readab= ility. Separately, each one represents a half-measure that would benefit no= one. The first does the minimal changes needed to get the relation-stats t= o stop using SPI, and the second does the same for attribute stats, removes= all vestiges of SPI from postgres_fdw.c, and adds some tests to make sure = that a foreign table has the exact stats of the source loopback table. > > The function import_attribute_stats() is a bit parameter-happy, but that'= s mostly necessary. I left the non-key parameters as all type char* because= that avoids even more "bool foo_isnull" parameters, and that allows the ca= ller to not have to rework the various stat types into their corresponding = C types (float, int4, float[], and the anyarrays that basically aren't cast= -able by any client program anyway). I'm open to requiring the caller to us= e the right datatypes for some of the parameters, but as I said there is no= way to "win" with the anyarrays, and even the pg_restore_attribute_stats()= function falls back to type text for those. > > To be clear, this solves the SPI problem, but questions about the design = of attribute_statistics_update() and relation_statistics_update() remain, b= ut those concerns are now isolated within their respective files attribute_= stats.c and relation_stats.c. The inefficiencies therein aren't really in a= critical path, so if we wanted to leave them be until v20 they could, but = if time allows I'd at least like try unwinding some of that. But first, let= 's get SPI out of postgres_fdw.c. Ok, I'll review the patches. Thanks! Best regards, Etsuro Fujita