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 1vdEkn-00FiYT-0f for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Jan 2026 21:38:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vdEkl-00AfUl-2p for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Jan 2026 21:38:12 +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 1vdEkl-00AfUc-1g for pgsql-hackers@lists.postgresql.org; Tue, 06 Jan 2026 21:38:12 +0000 Received: from mail-vk1-xa35.google.com ([2607:f8b0:4864:20::a35]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vdEkk-004bAF-1Y for pgsql-hackers@postgresql.org; Tue, 06 Jan 2026 21:38:11 +0000 Received: by mail-vk1-xa35.google.com with SMTP id 71dfb90a1353d-55b265f5122so396444e0c.1 for ; Tue, 06 Jan 2026 13:38:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767735489; x=1768340289; darn=postgresql.org; h=in-reply-to:references:cc:to:from:subject:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4OQ67UYdojDtS7fQ99ORYMUoSusxVbjDwON1/Uh9AMM=; b=NMzsAaF1eLv4Ui1myG8oZFCPFUpvc8/GseubEM6fko/EU/K2Pve1MWo6aJXD09JmwS JcRrauLxliHvWGyTjwji1xQYE2YpVVelQBrqBgLW5kpZoaWUgCVLvdXmYAKA4zvzLiEN 1pehbVGOEM4Wvtk4nTvAYlE85Dogr1GhxdZaYHergGC+x4cT4LQc5QNoo1fMtbMPlBMn NiDyD4DEMlMV+MWasJ2khaxc9et3ugemhjUC3gSKwP8egJXWNhMfWVwrQEBPckshTA1G OouA4DYEIa+GAZcrd+Bud/bACZkP231ODI5YDpmIZGDzTRacDjxcl228KbqqraOThefP cEsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767735489; x=1768340289; h=in-reply-to:references:cc:to:from:subject:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4OQ67UYdojDtS7fQ99ORYMUoSusxVbjDwON1/Uh9AMM=; b=bh30yZ0f34c9roJ8eMbEqJaaJKQq/iwBVUf9tzjcRVc7mZfQ15+A9ZDO5QvoyXlMr3 oS7a6hHKtdYMaqSkcBxGMsZx8Y4lmeINW7oQwtzGTqmsxYiYAav4JBXaN5yNJqDc9pzt 7yAo5pPoiKiTLdtvmiorXx18q0RTsDCOGYEmA87g+UEXsvie3Fc3IS97fZqAhb5VhCF5 nBRy6OJFckiOHcLMG75h19I60aAvqcysNZIo733pDH+rtMnN0DUH/OGlD5bzLCLi4L1m o/Pm9NYzzuBYIkRneqWBzpi89m6NTQfFAxuRUWqFSm35w/LEBXTk0Q5BvBMNZfFlrKxQ Zjcg== X-Forwarded-Encrypted: i=1; AJvYcCVtJnirrZ7Gct8zTTZ0zfSV88O+3nychpASepAjW/CXtg+tK5ez9t0usl26INxNd5jUE6zlKU8xr9DvSY8F@postgresql.org X-Gm-Message-State: AOJu0Yw4WtTdkRg4u/elitd9wTV5ducUUEXMHiHUPY+RkbO3TaIN8jcV 9m1gsEXbAmkrfRxdAFxzrFDdWut8h9a5Q96LuVLdOPuQZfO/ReULHCdI X-Gm-Gg: AY/fxX7BHHf1rkRRYummiq10+VKe60lmSwFa4NxifJl03Ioa1NXFs6lMLPH4qqeFk82 l4p8t/CoLEcen8h0omkcM4rnT1xrckj5iC5X79k2m+tNERnGgOhJCyFtD4kggCohyJgpSUgMnUn 2oOY9LnFh00r0FLmS/pRumw+GYINlt5g12w7ngJtfwVcD4IkyTH0ko7bW2Bz8BRnHDYzq3mBM4H edCfYPyFW5cXI0GJhHCOTLEwvzpYVXskUGET+59svDqhyHKGO5XuN6et/D5sLDSUeBMXuFsAtqn HAg7g4DY+Zkj2LtOXNHjIP9j7+ftmgb0C4S7FcUXSF2qwnRbTCgyxjAbkWsb3UnBLBs6UaL3Tl9 BevqMsy91chXJICKY/tSm8zC9GxpUPEo+d3PdGhR5o1jJdF/HCcKlNIAm958PpQJNFPPf8gOO8M voUzCGBQkm+UPNW9E1DrxXDi8i4ULZScdCQA== X-Google-Smtp-Source: AGHT+IH3cDYp+53Sjt2XNtTx87QoIFcnQSlwVAov+0mLLwfhCatohkFrRmgybSetSf8pFGqjdLDrLw== X-Received: by 2002:a05:6122:8b8d:b0:559:6960:bdf9 with SMTP id 71dfb90a1353d-56347fd2fe3mr97492e0c.16.1767735489006; Tue, 06 Jan 2026 13:38:09 -0800 (PST) Received: from localhost ([2804:14d:328a:a59c:6df2:dbcc:d2f7:5e32]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5633a209b30sm1055465e0c.8.2026.01.06.13.38.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 Jan 2026 13:38:08 -0800 (PST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 06 Jan 2026 18:38:04 -0300 Message-Id: Subject: Re: Import Statistics in postgres_fdw before resorting to sampling. From: "Matheus Alcantara" To: "Corey Huinker" , "Etsuro Fujita" Cc: "Michael Paquier" , "Ashutosh Bapat" , , , X-Mailer: aerc 0.21.0 References: In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, thanks for working on this. Generally I think that this is a good idea to avoid fetching rows from a foreign table to compute statistics that may already be available on the foreign server. I started reviewing the v7 patch and here are my initial comments. I still want to do another round of review and run some more tests. + if (fdwroutine->ImportStatistics !=3D NULL && + fdwroutine->StatisticsAreImportable !=3D NULL && + fdwroutine->StatisticsAreImportable(onerel)) + import_stats =3D true; + else + { + if (fdwroutine->AnalyzeForeignTable !=3D NULL) + ok =3D fdwroutine->AnalyzeForeignTable(onerel, + &acquirefunc, + &relpages); + + if (!ok) + { + ereport(WARNING, + errmsg("skipping \"%s\" -- cannot analyze this foreign table.", + RelationGetRelationName(onerel))); + relation_close(onerel, ShareUpdateExclusiveLock); + return; + } + } + if (fdwroutine->AnalyzeForeignTable !=3D NULL) ok =3D fdwroutine->AnalyzeForeignTable(onerel, &acquirefunc, &relpages); if (!ok) { ereport(WARNING, (errmsg("skipping \"%s\" --- cannot analyze this foreign table", RelationGetRelationName(onerel)))); relation_close(onerel, ShareUpdateExclusiveLock); return; } It seems that we have the same code within the else branch after the if/els= e check, is this correct? --- + * Every row of the result should be an attribute that we specificially s/specificially/specifically --- + if (TupleDescAttr(tupdesc, i)->attisdropped) + continue; + + /* Ignore generated columns. */ + if (TupleDescAttr(tupdesc, i)->attgenerated) + continue; + + attname =3D NameStr(TupleDescAttr(tupdesc, i)->attname); Wouldn't be better to call TupleDescAttr a single time and save the value? Form_pg_attribute attr =3D TupleDescAttr(tupdesc, i - 1); /* Ignore dropped columns. */ if (attr->attisdropped) continue; ... -- Matheus Alcantara EDB: https://www.enterprisedb.com