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.94.2) (envelope-from ) id 1vAjeD-005V28-UY for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Oct 2025 06:45:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vAjeB-00EatC-Jl for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Oct 2025 06:45:34 +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.94.2) (envelope-from ) id 1vAjeA-00Eat4-Rd for pgsql-hackers@lists.postgresql.org; Mon, 20 Oct 2025 06:45:34 +0000 Received: from fhigh-a7-smtp.messagingengine.com ([103.168.172.158]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1vAje7-002joI-2x for pgsql-hackers@postgresql.org; Mon, 20 Oct 2025 06:45:32 +0000 Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id 9B56E14000C5; Mon, 20 Oct 2025 02:45:30 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Mon, 20 Oct 2025 02:45:30 -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=fm2; t=1760942730; x=1761029130; bh=A9hSDtfp7u ffptfZoMbIQ9kiDpM6VCWuqw9dZxmCkQQ=; b=IgzZxXvqNbsLFi8JwoABM3JYM8 L+UbYV1e+KGdX77GAwxypBICT0l1S0Ds0zRqTjqruHmKCpr9IFOftTYwI2/PKcXl YLleYPgX1oAfeVIg9gwiZ+BnFhiZaREi3Wrov21Q2gYPnZj49gC0F0CGK5W0LQpJ E3KWsdICA/wZazm+jIV4ipIBJagLN+PGrdM+plopm+Rjtv2lXVwUkzbxdhNbybUt ujXcqyQxnriLFyji4D9sgDJNWwbh3MgyHtUv3rDV2Euoz+K4v5VnP12OKsYnmJwG oMxvUQ+pr5dAXfekcDWEhipj8g7heErPZQcX3KbxP0FBJ9cpXZrqp/W7mmxA== 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=fm2; t= 1760942730; x=1761029130; bh=A9hSDtfp7uffptfZoMbIQ9kiDpM6VCWuqw9 dZxmCkQQ=; b=zLEqut1UAs8DmV6r7x7tpSqAmjDjCZ1DgV3QJYt0ogmS/raS3RO quuH05hxs2lIRwMnY07i6pKRktNzG4HRyWjAxkKBJPQp2crHUGQRvZf0FzzDjENT MTR0/lcqFaq67mKreEYQrdouagHaRffsJUvW7ANu/3IsJWUGZ3eEaQr3VG5tJmC6 4EwH/GYudflOVwvDglZeW+Sg2HvpM7p/3+af2d2B8NM4hH36pDVZE4KESoOaSjIs XzcnIuYHutNmiKEGy8nE0BeSG5rDSP63iBa6Q4fgylHitRtdlyw8jZqCizqLN1uT qhMLOM06pAX3J4XLLiKu/XeVF7rBTBwBYvA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddufeejudefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegfrh hlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteelieefudffhffhtdetleeggeeg fffhkeeuveetiefgudduvedutefggeeivdejnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiidp nhgspghrtghpthhtohepgedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheptghorh gvhidrhhhuihhnkhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopegrshhhuhhtohhs hhdrsggrphgrthdrohhsshesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqd hhrggtkhgvrhhssehpohhsthhgrhgvshhqlhdrohhrghdprhgtphhtthhopegvthhsuhhr ohdrfhhujhhithgrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 20 Oct 2025 02:45:28 -0400 (EDT) Date: Mon, 20 Oct 2025 15:45:14 +0900 From: Michael Paquier To: Corey Huinker Cc: Ashutosh Bapat , pgsql-hackers@postgresql.org, Etsuro Fujita Subject: Re: Import Statistics in postgres_fdw before resorting to sampling. Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="rOPN3cpX+Pdn4BU+" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --rOPN3cpX+Pdn4BU+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Oct 18, 2025 at 08:32:24PM -0400, Corey Huinker wrote: > Rebased again. Hearing an opinion from Fujita-san would be interesting here, so I am adding him in CC. I have been looking a little bit at this patch. + ImportStatistics_function ImportStatistics; All FDW callbacks are documented in fdwhandler.sgml. This new one is not. I am a bit uncomfortable regarding the design you are using here, where the ImportStatistics callback, if defined, takes priority over the existing AnalyzeForeignTable, especially regarding the fact that both callbacks attempt to retrieve the same data, except that the existing callback has a different idea of the timing to use to retrieve reltuples and relpages. The original callback AnalyzeForeignTable retrieves immediately the total number of pages via SQL, to feed ANALYZE. reltuples is then fed to ANALYZE from a callback function that that's defined in AnalyzeForeignTable(). My point is: rather than trying to implement a second solution with a new callback, shouldn't we try to rework the existing callback so as it would fit better with what you are trying to do here: feed data that ANALYZE would then be in charge of inserting? Relying on pg_restore_relation_stats() for the job feels incorrect to me knowing=20 that ANALYZE is the code path in charge of updating the stats of a relation. The new callback is a shortcut that bypasses what ANALYZE does, so the problem, at least it seems to me, is that we want to retrieve all the data in a single step, like your new callback, not in two steps, something that only the existing callback allows. Hence, wouldn't it be more natural to retrieve the total number of pages and reltuples from one callback, meaning that for local relations we should delay RelationGetNumberOfBlocks() inside the existing "acquire_sample_rows" callback (renaming it would make sense)? This requires some redesign of AnalyzeForeignTable and the internals of analyze.c, but it would let FDW extensions know about the potential efficiency gain. There is also a performance concern to be made with the patch, but as it's an ANALYZE path that may be acceptable: if we fail the first callback, then we may call the second callback. Fujita-san, what do you think? -- Michael --rOPN3cpX+Pdn4BU+ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmj12noACgkQnvQgOdby QH0T3w/+KZ2rNqTABol7d7NoAUkBtesCwUaMz7KJPtsaIur8DfyknqkGSYikmbBf HrF7eyrR5UsBZ1TlpPgXswLUatAu7UMsJkec7v65pUx84Oz4bkTFbtc6IZ9McauH EoHRtzGLxEyj0G6vnPmlWC6YWzUH8A9dedg2x3JVidQR7URG3CbIO1ZrMgVsd0zy Wpl3jSBCYqiXlGEA5gpC3a2z6tihownpp+A1ISc3x8Jveo05yCqs3x5EyrFrL9kc N1q+NnxQR2pDdEMryuz3z+nF0jPUtj9DNTGn1rdEL+Xricxm8b2Iwyx4GlJVwTrB f32w5WGx0WQ6DxJhf8plLiGwx6ft5gMRNPdSjKWnVfAZM0O84FqMFxq19U51KGa7 PzoanhmeyldywsPO2D67PlPaxGxCsN+VRotPLB/Yu3hZOaN1Qw35BoICo4C6QnBq +vjNkr/VfacszfZcUKeQoCbzVW1EtZ+p/RS+BSmlHblA99gSlpXc+C978NDDp2jF DAC+js7r7hfRqLVjoMATtEZeFiwzfmF0KPKHZW9AIOaKtlvn1qfh0n+NVeGZwSar 8NEnrz2RZ4guLoUhNAWEXM3D1Qyget3155SB9XDhngkbW4wntyf4vmei9VNjQHxn J9Hti+/HAjHVTTOA/tWCzhRZjAQ7W8WNLJ7AXDWz09FKAlTdK6k= =ITRu -----END PGP SIGNATURE----- --rOPN3cpX+Pdn4BU+--