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 1vwr1k-00HPY3-0d for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Mar 2026 00:20:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vwr1j-00EQd3-0O for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Mar 2026 00:20:47 +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 1vwr1i-00EQcv-1B for pgsql-hackers@lists.postgresql.org; Mon, 02 Mar 2026 00:20:46 +0000 Received: from fout-a1-smtp.messagingengine.com ([103.168.172.144]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vwr1f-000000022BI-0gjD for pgsql-hackers@lists.postgresql.org; Mon, 02 Mar 2026 00:20:45 +0000 Received: from phl-compute-09.internal (phl-compute-09.internal [10.202.2.49]) by mailfout.phl.internal (Postfix) with ESMTP id 29991EC060F; Sun, 1 Mar 2026 19:20:43 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Sun, 01 Mar 2026 19:20:43 -0500 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=fm1; t=1772410843; x=1772497243; bh=fzW1Jh+vss ZIVt2GkslNyBMvd6p6d0DEvIBur6O0d/Q=; b=Hp1z1xpnPHm+QGf9/7c3efpvVM PLol1MOAmiFd1kLfssygT2lzMWu8YMb95s3b8iFuWHhstvGQs1jqF5iH3BmmOumb 3LlqrtZ5H4sjPCzajyjh1IA7uvlgBVhZMo6PKV4EwV0kP0CTiLJVQyZBtkH+HGVZ z3LHgmx0ePVp95q1UsA0wAynmS8moEjsC1YiB5XVKsPAg2liCbjKSjntsSkGMjvQ 4YviBYyhqMt2VjdeOEM5BYr4aaHPwNScVn3d/jGnZ2czXt3NAeDkyWbiwQozhf4c LV2fiJMTa/NdgDpxxkJaAHVhe4bH9bjYvcwZ9+TDjNA2PKdkFKk3FACcyC5Q== 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=fm1; t= 1772410843; x=1772497243; bh=fzW1Jh+vssZIVt2GkslNyBMvd6p6d0DEvIB ur6O0d/Q=; b=LPFXJHXhin9N7uARUmMp8mqnK1apOxv5cL+T9Z+c8Uw74GsS6xe n/w46lc9JmSuHb/FraHwroVI9Re/tZjO7LTBwekaL9xdZfPG+/rCNVMeGQVxLGWY +FPkkpnVIAJjbC717hGYDxm4MxieIh9q3T4tD2yx+i4+a3hd2TG9LV2gJE26OjA7 +1yR2uXqDySVkF2yHt6KeRMumJ42MnQh58KjNwuZ47PzeRxvKfki2U75I3oa0pmY TEYY1Hv3ezwUbSmtqVsGRLhmGOzQkARpvAlGrXmfV1TUQuwJ6pJtXoZHORs6+gLQ gtCRdJE3QoaBIjm4J0w7/Ypq1ESNt/YaW4Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvheeivdduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegfrh hlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttdej necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepveetjefgjeevgedukeehieeuieeu ieevueeiudegheevuefggfduueelgeelieetnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiidp nhgspghrtghpthhtohepgedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhird gvvhgrnhdrtghhrghosehgmhgrihhlrdgtohhmpdhrtghpthhtoheptghorhgvhidrhhhu ihhnkhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrh hssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrghdprhgtphhtthhopehtohhmrghs sehvohhnughrrgdrmhgv X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 1 Mar 2026 19:20:41 -0500 (EST) Date: Mon, 2 Mar 2026 09:20:37 +0900 From: Michael Paquier To: Chao Li Cc: Corey Huinker , Postgres hackers , Tomas Vondra Subject: Re: Defects with invalid stats data for expressions in extended stats Message-ID: References: <92BA3F52-47FB-49F2-A156-551D7BFC326E@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="kizv41p94PF7U47n" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --kizv41p94PF7U47n Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Mar 02, 2026 at 07:39:45AM +0800, Chao Li wrote: > But why do we still explicitly free the stats array? My concern is > mostly about =E2=80=9Cpartial free=E2=80=9D: either free everything, or f= ree nothing > and let the memory context clean it up. =E2=80=9CPartial free=E2=80=9D te= nds to > confuse code readers, and future readers may keep running into the > same question.=20 Not necessarity. We have plenty of these patterns in the code with such partial frees. At the end, two things tend to take priority: the readability of the code as well as its efficiency because repeated pfree() calls can be more expensive than a memory context cleanup, particularly in hot loops, though doing pfree() calls may be better in some cases. In this case, I see a better argument with the code clarity, as we use the same array for the stats built with attributes and expressions. We also cap the number of expressions to 8, which puts some control. But at the end it does not really matter: in this context ANALYZE makes sure that nothing crosses the processing of a single relation, even with a transaction analyzes a lot of relations (same or different). -- Michael --kizv41p94PF7U47n Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmmk19UACgkQnvQgOdby QH0BAg/9EGpl9HL43R9iwwo6qmRvAflmmaUm7rAJVLrktDgvGbsQ0Qyd/lsZGH3X 76M3Cl4EAasT0cpA3SJyktR62skld83Db6luCSTMJJJlCUcgRfew4eGBPVFBFG4A IzXWK5SQdpmjyMj+Ys3e1R0DwNShhuylYKwm/z5a94+8BsrJQFkK3DNuOhUgfHUy moreJkzk6vQnM0sXjBE9GOgMWQ6+pmNeEaMOQyjTfp+GFwe6IpTHg3z32pxxLtCj RXGFw3ztn49FGOLtH9a9LIoNCf9IBG0vWS7lzMHGoVnxtdPhBY80JVjN7M7PV3A5 cJFbrP8oSIya5pNn85uxCJlDJcXzHqTzlJpOXlaj0Mr2Td4C5H9AYoXyoX8fTD3l TfD8x3gwsVogPmfGUGkoFut4AEf8m5yM1sJZgFnXyOHlS9H4iYttBouvIsb9sp6G rCxi+OJqqSXllUP1rFxVBfauI8u0fbHhPwLdYL/+L2oBHOSqr8MnlcmnEzlhPkRa 11nHaMDiQYbrR/+Vkar3RGaTYgE610151FbjCQ2abZvVeMR1kj5rJ4DZI0K2w8+I NOLM7qGHg/w9Rx0SESeEXFp+1ZQvaThosx5xgWvjP6oSqitV4C68WWPTO0xJ4rkZ rLS+MRW2g5QZlIf/MhweXijhC36KEZNACxxJpHPZT25WIvYDxPs= =l8Vv -----END PGP SIGNATURE----- --kizv41p94PF7U47n--