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 1vwprN-00GCNt-23 for pgsql-hackers@arkaria.postgresql.org; Sun, 01 Mar 2026 23:06:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vwprL-00EHSs-0m for pgsql-hackers@arkaria.postgresql.org; Sun, 01 Mar 2026 23:05:59 +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 1vwprK-00EHSk-0w for pgsql-hackers@lists.postgresql.org; Sun, 01 Mar 2026 23:05:58 +0000 Received: from fout-b4-smtp.messagingengine.com ([202.12.124.147]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vwprG-00000001vvX-1Qzq for pgsql-hackers@lists.postgresql.org; Sun, 01 Mar 2026 23:05:58 +0000 Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id 824A81D00052; Sun, 1 Mar 2026 18:05:51 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Sun, 01 Mar 2026 18:05:51 -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=1772406351; x=1772492751; bh=HsfOGBre9G 06DxfNCY/7DnJ7aTXJt2oatRKS3ZQ1yG0=; b=X764d8v8u2SEFlT+cz8rJsyYsG siR9dj5dodcgqGlU21y/xYvbZ2Gmi+Hsoa0OgCg1QCXHRd5IJcM0UnrFTzO0bDet ZvX9jOiapDbQgH23s4WfRi/L7FFRafwzhSZtZdSjFe6H1WsxG/Q5sg/oNTMUMiw2 WUF9fH9C9vlH93IwfilTEw9lqFXEYY/GSTLbp8mgyeFyekEdoB1vxSUYrfbdT51s kOatL7fF4F10p8sxa4MlzgvqRj/A5/5lgE0w2+tPQX18RllMakRhYdwlRSN6nKXk y2W5TDRhuNC6i0VKyiX3T6Fzp0otYO5wPp3iBh4E7tBGC46eFv1wKvEaKu0A== 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= 1772406351; x=1772492751; bh=HsfOGBre9G06DxfNCY/7DnJ7aTXJt2oatRK S3ZQ1yG0=; b=PsrnVjmEbjHWUeRAEkJi4BTDZQD0ptKBVgNw19KDM2BCb+Nfe6Y O0cqY2GnHoHFaamT2e2ZPz2WCqrae5TLQviBv11GXwJg0YzXPK9aOmyroiTP7n2S nkKT063BXJSmavmtaQi6hvO2uOxySad6M7TwBE1fkta8YGm67EYjpBw/Cy+JcgEE MQrZ+85P+zDKO5R3a+Taco9fw2SBUWgRz5DE5nQGkKP7ZWpPODLYVRQABnlBzcCE Udqf/IcYNMLmzdSnlU2Y+dGJsjmrd3HoykqgTCOWuY0VAz1eD316WhDKRhcx1Mot 2KL6gcPZ2J1xvh8WKYJ7u/DEudosFvFZw+w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvheeitdeiucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegfrh hlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteelieefudffhffhtdetleeggeeg fffhkeeuveetiefgudduvedutefggeeivdejnecuvehluhhsthgvrhfuihiivgeptdenuc 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 18:05:49 -0500 (EST) Date: Mon, 2 Mar 2026 08:05:44 +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="dKFa1Rtj09hQ17ke" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --dKFa1Rtj09hQ17ke Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 27, 2026 at 04:33:24PM +0900, Michael Paquier wrote: > On Fri, Feb 27, 2026 at 02:51:40PM +0800, Chao Li wrote: >> Here stats itself is destroyed, but memory pointed by >> stats[0]~stats[i-1] are not free-ed, those memory are returned from >> examine_attribute() by palloc0_object(). >=20 > I am aware of that. This is not done on simplicity ground, keeping > the cleanup of the memory context to ANALYZE in this case. About this one, something worth noting is the beginning of do_analyze_rel(), which does the following: /* * Set up a working context so that we can easily free whatever junk ge= ts * created. */ anl_context =3D AllocSetContextCreate(CurrentMemoryContext, "Analyze", ALLOCSET_DEFAULT_SIZES); caller_context =3D MemoryContextSwitchTo(anl_context); So these extra allocations would just be freed under this memory context umbrella once we are done processing a single relation. This works even if we begin to repeat ANALYZE commands that fail to build some of the stats in a repeated fashion in a single transaction block. Code simplicity and readability is just a better choice for this path. -- Michael --dKFa1Rtj09hQ17ke Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmmkxkgACgkQnvQgOdby QH0dgw/9GUYnYQLWQrw5PGGS3gvf6FAhbC1n55oZqlVS4j1z30MVwgC8Qjvy1ozb j/bzs6er0n2OVpSbQSSHZViMvzpTZD3j3VSKYMshLmoADq87jLFAazMn6WgY03JE u13njTVV7dVvGklHszltpfCkjDGlBsY00V7ByV1VifXZulsO6A4YJwBlVjnv5HjW LX56U6LRshs9qiYRk6/AAyTNTj7SSlJ1dkl0DTK1BKBPMvRGn6aO71dtOfvbmhXE ekpaTbQLxo8fga/xZoeQtjLPhZXFoCGoKCsLndI7y6aTg3leV2QpSe0TwzUEho9w e8Gj3ct3xPMg1ls9qHSUVJp3F7xiy3dG5SALT/mx/Ev5ByPGSlTsa/ikCEFBu0Mu EqdhWk1RqZtxUlEB44BugElatxVnd/ytWEMwPfDlimWdPXbB+NtnQPOjFn0i9pD/ M91aAP81QyfSWWUxwh2xqX69LPs2cTSMDIb0kngOAtgbt4A8f4kRYplxbi4FLP8y Ttmx/gOao8ZpY7I3s1TpcFLomiSh+E8y2RalRRbjDggwMEv8JhbQerfR854mVI+U fVEWqO51xsssEIZ69bl4AkESdvXFF6i8/0dmqFpkzmmIZfj/AZl5YZwaMgHf3OVC vEktS/V9xBRtjk6hAyh+eLOaU940dGxdFl90RJA/Kwkl1d5rIFQ= =sG2K -----END PGP SIGNATURE----- --dKFa1Rtj09hQ17ke--