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 1vgJAi-00AjTJ-0o for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Jan 2026 08:57:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vgJAh-00Fr78-1U for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Jan 2026 08:57:39 +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 1vgJAh-00Fr70-09 for pgsql-hackers@lists.postgresql.org; Thu, 15 Jan 2026 08:57:39 +0000 Received: from mail-dy1-x132c.google.com ([2607:f8b0:4864:20::132c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vgJAe-000XHy-0D for pgsql-hackers@lists.postgresql.org; Thu, 15 Jan 2026 08:57:38 +0000 Received: by mail-dy1-x132c.google.com with SMTP id 5a478bee46e88-2b19939070fso1599226eec.0 for ; Thu, 15 Jan 2026 00:57:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768467456; x=1769072256; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=dg+e9gAko7ZbTx9VUmf5fDHK1ynC6P48da25d4niSik=; b=Wn/WgLFiWrmchLyPREYcO2OKLHzLT242QhY56uoKb/hhATSKmLzhWvfzhoXzyErtjK kcO7kYGBhWgCyiibxZezzkL9OUfFJRNS+RCgY6HVwMM/vuXrQMJXsABlNTp+/xB+CR6A eotOtx62hJetSXtFT7Ac1r9sItIwSkFzt2TUKNe0dgZat5I7fdf+Qn3WqeWfIsacktuv WzW4nmlyakLUXdlxEbgtYsVWjVlIEvnrDoCSyIlxe1JGr0ZIi9bwQ/a5wn9gIfnoSJ7Q kYJSyah587XZ+qVfy2dm7io67mJtC7Vzu1frjJorAoFO3AQZ+MNVXSQL10QL+1uhCBUr mwFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768467456; x=1769072256; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=dg+e9gAko7ZbTx9VUmf5fDHK1ynC6P48da25d4niSik=; b=RkGtmpl39AQ92UgIK+tMGf2LieaNuSfFmHjnafaxdl1gs81myNzwMuWuTPuyzMFyim p4H/RIeWjhdL7L6rVP/U8Hkfw9rFC3RqIhKiQb8BrcBzu3krvWBS422L4AzfxuIb/uC6 CBOqobmFvwzAShgRv/xoHhJM3KMPjJnPwGeXUtUulRFg/ogTet1o7HWJRCmZO0c5Q/sZ ZJfTv3jveyGQV1BGHk1OZPQXft14FK+MY1eK0QyqGiqSoalWUDy8Ud1vaRs6s5A2PHHF I9bOFneINlJNi6UcGRSZ699a2FaeQllP5uxhIISxF3jhlC20z/D6pRVyArvNLJfAAR02 pAnQ== X-Forwarded-Encrypted: i=1; AJvYcCXUIBUiDgA2h2nd2aiSEPasMPUZKTEEXGRlZv3IAljXAckOiBExUPUg5ViDaFU5ASBy24FHu6Ed8kNfgraS@lists.postgresql.org X-Gm-Message-State: AOJu0YxBA0JzHbJE4tLHhf6L7heUcAaYsbwntpAFJN8nAWw7DItUaOOC NyjR6VMPyNWokPrdZvqmnSFT4bAkZywZI7tFctVLRE7FPmSf1otIRvg6 X-Gm-Gg: AY/fxX5HyGpkuaZqWfJp1ku0FVpcnnLbS3p1DLvpl+4178G3WHK9vTon86bCbPhIx7U DffXutnSvMrlVwSdP4oY+7ZL23uf63HPZbNDNUCVWcvyZyM0mY4Qm2Sap485ZSWIJlrgpri0YT6 18psvPY/zW/H23s1yqlAi2mnZK9671Lu+HpWY1RwqCzo3oMhtowYrVTkVinBpt3IZ1NgcncKjN2 t6g6B1lsD1UZi7cmxjXd4PUI2dEGz+uJQoJahZwTB9fpv66J8vUQPlYYDHYLmE9UvW86qHtCVZJ KDbEfTKGx5hT6ejAOLA8grVTk4R2xbJK2CMWzqL6Zi8Ey94+Xz2Em1bikv/NJ/d1tzVD+IDAetN yYGdjiTq4SucO2S62S4EoDJJ6NTtry6EVvu4CDBLJipvyH+SqFbBwL5++/bZ5Q24UrfK/MnGQox ZdnECIqnd2SEdgWLyh8gL+ X-Received: by 2002:a05:7300:5410:b0:2b0:50b1:d963 with SMTP id 5a478bee46e88-2b486b53bd4mr7159263eec.3.1768467455674; Thu, 15 Jan 2026 00:57:35 -0800 (PST) Received: from smtpclient.apple ([142.171.105.12]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b6a5727b34sm615085eec.23.2026.01.15.00.57.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jan 2026 00:57:35 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81.1.4\)) Subject: Re: Extended Statistics set/restore/clear functions. From: Chao Li In-Reply-To: Date: Thu, 15 Jan 2026 16:57:00 +0800 Cc: Corey Huinker , Tender Wang , PostgreSQL Hackers Content-Transfer-Encoding: quoted-printable Message-Id: <58FB2F62-66DD-495E-83A6-607903834272@gmail.com> References: To: Michael Paquier X-Mailer: Apple Mail (2.3826.700.81.1.4) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Jan 15, 2026, at 16:09, Michael Paquier = wrote: >=20 > On Wed, Jan 14, 2026 at 12:57:45PM -0500, Corey Huinker wrote: >> Some of the header cleanup work required adding utils/typcache.h to >> extended_stats.c. >=20 > Thanks for sending a rebased set. It is a large patch, but most of > the changes are super mechanical, making it sort of "simpler" to think > about the whole. >=20 > Anyway, I have begun a review of the backend changes, and found one > independent piece that was useful, leading to 32e27bd32082 that I have > just applied after some renames and a couple of fixes. >=20 > Then I have spent a good portion of today looking at the backend > changes, with first a focus to extract the "clear" function as it is=20= > useful on its own, also because its relation lookup logic is the same > as the restore function. >=20 > And then, this block of code has been giving me a long pause, because > it was fishy, and clearly wrong: > + /* no need to fetch reloid, we already have it */ > + RangeVarGetRelidExtended(makeRangeVar(nspname, > + RelationGetRelationName(rel), -1), > + ShareUpdateExclusiveLock, 0, > + RangeVarCallbackForStats, &locked_table); >=20 > A shocking thing here is that we build a RangeVar for the relation of > the extended stats object based on the *extstat namespace*, not the > *relation namespace*, and that we do so *after* opening the extstat > catalog. Anyway, I think that we need to redesign that, and for > consistency's sake do a RangeVar lookup *before* even trying to touch=20= > the stats data or open its catalogs. That would be beneficial on > consistency ground, and one piece where I think that patch is designed > wrongly is that we should give in input of the new clear and restore > functions the *schema* and *relation* names of the table we expect to > find, so as we can enforce first a clean RangeVar lookup, then > manipulate the stats data. This relates to 688dc6299a5b, as well, > except that we would be stuck with an incorrect design after release > if we are not careful because the function schema would be stuck in > time. This has to be right from the start. >=20 > All these changes have given me the attached patch for the clear() > function. Another piece is that we did not really check that a role > has the MAINTAIN rights of the relation where we want to manipulate > the extended stats. >=20 > A final thing is the location of the new SQL function code, let's put > that into a new file, named extended_stats_funcs.c in the patch. > There is nothing in the new restore and clear functions that require > extended_stats.c. >=20 > Finally, for the clear() part, the attached version addresses > everything I have found during my review. We will need to make the > restore() part follow the same design model with the Rangevar lookups > of the parent relation, or we'll have trouble waiting ahead. > -- > Michael > Hi Michael, Here are some comments for v24: 1. ``` + inherited =3D PG_GETARG_NAME(INHERITED_ARG); ``` Should this use PG_GETARG_BOOL()? 2 ``` proparallel =3D> 'u', prorettype =3D> 'void', proargtypes =3D> 'text = text text text bool=E2=80=99, ``` Should we define proargtypes as =E2=80=9Cname name name name bool=E2=80=9D= ? As the doc change mentions type =E2=80=9Cname=E2=80=9D for the first 4 = parameters. Maybe you want to avoid that because Name is a structure. = Anyway, I don=E2=80=99t have a strong opinion here. 3 - extended_stats_funcs.c ``` * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group ``` This is a brand new file, so the copyright year should be just 2026. If = you search for =E2=80=9C2025-2026=E2=80=9D, you will get a bunch of = files, they should be created in 2025. 4 - Given comment 1, no test fails. I think that=E2=80=99s because all = test cases use inherited =3D false. Maybe we need a test case for = inherited =3D true.=20 Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/