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 1weAW1-004bub-2f for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jun 2026 11:51:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1weAVz-002xLQ-1G for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jun 2026 11:51:03 +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 1weAVz-002xLI-0F for pgsql-hackers@lists.postgresql.org; Mon, 29 Jun 2026 11:51:03 +0000 Received: from mail-dl1-x1232.google.com ([2607:f8b0:4864:20::1232]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1weAVw-00000000mST-2bIw for pgsql-hackers@postgresql.org; Mon, 29 Jun 2026 11:51:02 +0000 Received: by mail-dl1-x1232.google.com with SMTP id a92af1059eb24-139f71a5201so606696c88.0 for ; Mon, 29 Jun 2026 04:50:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782733858; cv=none; d=google.com; s=arc-20260327; b=G5kGSRxQStkB+WK94FwK7ly7ji/a4pkJ22mP1vssSUVxkmW8TLUb0yhRsflA6s9SdB 9I3FzcDncPDcqX4vPri/Q438HHgwat3WjFYzXX9PoBfkaLLAtX7qbihwEEXecuZP81Nr vW1o7/2iuaGqSwLUm4z3AgWKbprSeB9N0si/4r9sJCE4ngt3BC5LpiZK5NhNNUFqAMtq gDGtEhVrB8vgst1UxQQATMJ/OzxmLcsCUaCcjEDkcVBtGO/byokiAJjD+pL/zAQSAHdE 1kDqbsYONm1117/zKofPyzwRTaKTAMnkTVVWbNTPU6Oxyp4FqYUKD3K64SKMF7ZjIrhh n80g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=RQYxSSSw8BBaFN3LagpGB+xwtLO04p7d44MSR/xiIWQ=; fh=YXgvSdB4RCnJ9JaoATFJpmOw7nZbikMee6yZkrpieKk=; b=jaLYQuIl+Yin6ewlr8/0Wu0T58HEuyJJr9wdHBXVU1SMMnUCP0eDVjQkapp0cu8kE1 fVJEjwJDQ/2CbL555rLpYkiqRywMuuM8YE9IIPks8PbqPZPR6pULHLe7UbrLhQoG3Z8t syKqqBB2uzR0bCimeO8AQ5MXXWVLU6wHRwtPgdad2SiZHfoUPCT95bRStNjaxat2OPYh qapVj1ROKCMy50aYTMYodg1/aXfjA2OXyxfqMQWQ4i7eekX/oBUrNGFUvHZ1JxmREcQP k0rJnzQd5m8Z1rdV5UWZdUjT4cDwCrRsC1IZxe0c0Ylszz9UEfgxs7ORfPYvWkFJRtMa xSEA==; 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=1782733858; x=1783338658; 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=RQYxSSSw8BBaFN3LagpGB+xwtLO04p7d44MSR/xiIWQ=; b=NWtacPKagcbD89XY1eLyOSJJgTjhM6XWwD8uJGOv5ngP1+osD+4RmYPldRj7RrE+C4 LEbojf05fdpy9hbzElK9KXw0F+bDI5rJEdHziVV+g+JIQTd6qndVumQrIb908rEZ6kKz D7mJ+fpBJXj1H5YqF9uGKtLNSDo8saJMMHevooeEcZANgxkTBXqwcdYAxDGdsFn0Taw/ YJn4cmniKxcQLtIWmmx0ERFKPkvKRJZSLQ1Hu+QqmhhaRkOAONjjufHFk1A/dysropq3 rrcHVtmNrzkIs6BE1mC6jkoub+Eb1vCf9Rf/160XQuPXJTe/3RLRiLfwPEL5PpG0vXH8 nB0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782733858; x=1783338658; 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=RQYxSSSw8BBaFN3LagpGB+xwtLO04p7d44MSR/xiIWQ=; b=etYPJP4//q8VMaYP1Dzwp79rKaq0e7hlqrM213t5wieUaKWP1eIDlwUcrPIC104x+w 0qcxCDF6vKs5VRxb0Lc8dH82MMtXh2qQdgLU6MwMyi1vmmxcD0WH0/kxCUT60v8qiDAc gNs1dDSuLsitenmOAQTtweOkkSeJ9V9/dPpjDggMsv2Kc7ah0D9FP/BdZcHFO6/ix6fD VfghknNE9kB3isRtmDh1on44s2iHBEafRhJftyJvIQ286fXEvjgtZCbfJG+zfCczXrjs YUmlr9+/WJDOj6gFMghSvq5KsajkwYuWXzYWMkF9cf4io7NvQI+AmuaS/zGKDcpxPlc0 xUaA== X-Forwarded-Encrypted: i=1; AHgh+RoPEZXlIM/ty4Kw2nJ5Vk4JrCZLVs+kZru6ZiW0kmetDR+cvD1/S9dZZKErMlV0oESbJZJa4HPDfUnN9z9Y@postgresql.org X-Gm-Message-State: AOJu0YzihQ5+ezFDaLhVXdJWRZshQqu9Jw9ev1njn8+Yj5uI0DNloqcJ LxfgJHhjr7QdXf+kySL6CY834bqQgBT662UnP6YY4sskzfMIUfgS3DazMdkGTJ191YHC3ytUTcD GM+UK/7362Vn8PHOI+NgTlERJdTf2SPA= X-Gm-Gg: AfdE7cngRu0sYag+2BNjyRibndjrrAjjlpzDJmsroeE9CB90sDPrvbpdS9DtvoRAYeg z1kxaZF2xxTfavYQnUE0dhkTDUMTSBLFEie+xBJDLArMCiBDB6t+YuB0Fc/vrsp+Sxr4LJAE0zc ntjcEzDPsysbO7nRdqltrVpX8N4lWuQQzaS17OUvIufprMTOgP2m+oJFOwcKKVGtkYSyfcE2Bl2 oTU6AyVu10iu8YcXX8hBefHlPAGqDFYLmmE8E/1SMcbaqnpFBisXN0VlqMCOqBNb8H1VJdsdejT F4zgYI87kNQJTPcbSz0oXlWYFSXI1tf2vaOXZe5TNt0H8x1Xx+aC3CgkhE6RymkdnCvpXMLPyCd YQrmRap34bgqtwHws46KaT+I684jFO5/GkDrVDRST X-Received: by 2002:a05:7300:6905:b0:2c9:ee15:a0ee with SMTP id 5a478bee46e88-30c85a5cd1cmr15495874eec.12.1782733857775; Mon, 29 Jun 2026 04:50:57 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Etsuro Fujita Date: Mon, 29 Jun 2026 20:50:45 +0900 X-Gm-Features: AVVi8Ce00268mduU_0KbzQMEUD00JRaRrOb_gykz4S6XUzY7MO6zbaGItACruRg 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 Mon, Jun 29, 2026 at 5:14=E2=80=AFPM Corey Huinker wrote: >> Requiring Datums simplifies things greatly inside the existing functions= , but pushes that complexity to the caller. My first proposal was to keep c= omplexity to an absolute minimum on the caller side, but your comments make= me think there's considerable tolerance for more complexity on the caller = side. > > > I've had some time to look this over, and it's pretty clear that we don't= actually need the whole positional FunctionCallInfo, we just need the fcin= fo->args of it. We also need the ability to pass statistical values along w= ith the values that comprise the key of the relation/attribute/object to be= modified. > > There are important differences in the parameters needed by the different= types of functions. The pg_restore_*() SQL function calls need to identify= the schema+relname of the relation being modified, and already have all of= the values as typed Datums, whereas the internal API calls already have an= identified and locked open Relation, but all of the statistical parameters= are just cstrings. > > The solution I chose was to create common functions that take a relation = object and an array of just the statistical parameters. This requires the p= g_restore_* functions to resolve and lock the relation themselves, and then= carry forward just the subset of parameters that are statistics (right typ= es, but wrong number of arguments). Conversely, the internal API functions = need to map their array of cstring values to the correctly typed Datums (wr= ong types, but right number of arguments in the right order). > > Attached is v2. The patches are broken down into very small bites to aid = digestion and to confirm that tests pass after each comparatively minor cha= nge. Thanks for doing that work! I like this refactoring, but while it's rather mechanical, it's pretty large, so I think it's too late to do the refactoring at this time just before the beta 2 release. So I'd vote for going with your v1-0001 and v1-0002 and doing the refactoring in v20. As mentioned by Robert, I don't think it's good to call LOCAL_FCINFO() in import_relation_statistics() and import_attribute_statistics() to call the guts of those functions either, but that is *consistent* with the existing way pg_restore_relation_stats() and pg_restore_attribute_stats() do that, so that is actually not that bad. Also, as you mentioned above, it's inefficient for the new API functions to lock an already-locked relation, and validate an already-validated attname/attnum, but I think it would be negligible. Best regards, Etsuro Fujita