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 1vvri1-006vqN-2S for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Feb 2026 06:52:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vvri0-001TAr-1Y for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Feb 2026 06:52:20 +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 1vvrhz-001TAj-2z for pgsql-hackers@lists.postgresql.org; Fri, 27 Feb 2026 06:52:19 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vvrhw-00000001RUU-1UGu for pgsql-hackers@lists.postgresql.org; Fri, 27 Feb 2026 06:52:19 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-2add623cb27so11187665ad.3 for ; Thu, 26 Feb 2026 22:52:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772175136; x=1772779936; 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=gfDCA0RtUBgarcWs7LotD1Aj8rgYwFri3yFC6QzfPP0=; b=R+JPS1o8Mx6ZuWlCaJmYt0tUHQGPphS9UxRA9JUv34nUIs0luEdrO4xV4PWiXn56JP InBOIudnlMwy5ec770+dgvSt/jRSSCFWP7unN5VBkeOIn6Nub7zXKn6Qb82LjAmaxu9d 6ljtPgPfps0ZqKAMTb8ilwDOXUpUxMHMIx/U5izj0DBi+79Zwj75Jtgdg1NJlJQyebom TehBO3c388qtRtQ47kdzJAwd6AYcPOP6gI0xBu1vkQEsTnqPnkN7s4uh5wUH8TsQfyGq FvpGObMSljIQ+YQGLDPxUe45BtpQirDeXS/P48KEv8IRxikbuqzL3rFT1HIi7xYAbfE+ zQag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772175136; x=1772779936; 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=gfDCA0RtUBgarcWs7LotD1Aj8rgYwFri3yFC6QzfPP0=; b=Q3iXqheFniSIQ/fUTwZv1AqkEN2ERrroVH7Q2cdsyOvkCBB9VPUkTuB+A2Ik06EIKc 0qYd8QW+N2V2GsG9Wvcxq+AotjC2/0SxmyOJLlxmGv6K4Dm2thvAaIn0zXCRULrrSlqD FMSdZ/r3NXCTFoQWCeAq9d15coDspsiKDi/YA0Mr2HjfUnL7vgiL2GVUxA8nlEDAHgDv bnoa7MuQo6FtQ/ySwBo9lAC4oQh+35OgI1am+g5xskChMbR62ilnFPJBbhKmUJwsuSmq SSGKSSwLTQC1v4Br+Y9ZnwOxoEDS7PbeGHcoADpBliEjeENFjYrt+HLr6Is6dqQwzzJd X8jg== X-Forwarded-Encrypted: i=1; AJvYcCXKsPdR3dYBdFOYSuUGib6zMVDKmStGHEytzbmfIDyZiR1d47Haro6ILq2b6UQUH8iQ/FCrh3YigtKE3N4m@lists.postgresql.org X-Gm-Message-State: AOJu0YxfOZ7fZ2C62gea8wvKVWw8FGxJFp9vIYsrUkdFEdyGd0btHdCm +DaC7mv7BCcAAG6kr1keCxPlVY0AsTQBpGsmInjRVNHyUufPxwARp1d8 X-Gm-Gg: ATEYQzyotWQIy6MOuI8Odxt45dDiy2SfUslXRSmRpVqlfy6+YuiaEpXHEwnplscnQ7Y nP0jFMj42IB5hkYXZlZ0BzWNm9nFbNUSwExlwOo2my3wb8vc5j0uTlA8TnBjp3UgAX9KC5BWbxZ Juu9pRZSZlubNdyes6Ioh15p+DKi4fGPqgMhdlnY1WTF4y6tbW+5CCm1OEl8xGmOya4rlZk271H XALHQa0i6PHvHRwdPRLruzCJdZ/F/8g2vRWkyasid7lIIr+np7X6dDiGd5/waEoKyicBNcB3dKG cJFIwYu5WUGc0RsJD65t5tMGPvBDjwM8IhpXooSznBoWWwYBNYOJUuQ6VFS4D+3lzi1Rho69Xp5 NrMLF4cEwQQiddcN/DTwf31vPTnc4UArD26z1ymE4xMMCmwnSxm4cEmS7q6wfg53FgkD/u+dv4X oc32RmTrYIfkg0Jkt0HRvalf9SJORgije3HlMAnvJaVA== X-Received: by 2002:a17:903:2410:b0:2a9:5b28:94c0 with SMTP id d9443c01a7336-2ae2e3cdea5mr14910145ad.27.1772175136510; Thu, 26 Feb 2026 22:52:16 -0800 (PST) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2adfb6a0409sm68914695ad.44.2026.02.26.22.52.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Feb 2026 22:52:15 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: Defects with invalid stats data for expressions in extended stats From: Chao Li In-Reply-To: Date: Fri, 27 Feb 2026 14:51:40 +0800 Cc: Corey Huinker , Postgres hackers , Tomas Vondra Content-Transfer-Encoding: quoted-printable Message-Id: <92BA3F52-47FB-49F2-A156-551D7BFC326E@gmail.com> References: To: Michael Paquier X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Feb 27, 2026, at 12:25, Michael Paquier = wrote: >=20 > On Thu, Feb 26, 2026 at 10:52:48PM -0500, Corey Huinker wrote: >> Patch applies for me, but there seems to be some user-specific stuff = in the >> test, which causes it to fail: >=20 > Yep. I've noticed that in the CI a few minutes ago. I have switched > the tests to use a query where the owner does not show up, leading to > the same coverage without the user-dependency blip. I have checked > that this version cools down the CI. >=20 >> A nitpick about the test - it uses a plpgsql function when we've been >> moving such trivial functions to SQL standard function bodies for a = while >> now, and they were introduced back in v14 so there's no backporting >> concern. >=20 > No, that's on purpose. Using a SQL function with a body would not > trigger the problem with the stats loaded at the end of the SQL test > as we would skip the fatal call of statext_expressions_load(). Based > on your confusion, I guess that a note to document that is in order, > at least, so as nobody comes with the idea of changing the definition > of this function.. > -- > Michael > = A few small comments from an eyeball review: 1 - 0001 ``` stats[i] =3D examine_attribute(expr); =20 + /* + * If the expression has been found as non-analyzable, = give up. We + * will not be able to build extended stats with it. + */ + if (stats[i] =3D=3D NULL) + { + pfree(stats); + return NULL; + } ``` 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(). 2 - 0002 ``` /* * int_custom_typanalyze_invalid * * This function returns sets some invalid stats data, letting the caller = know * that we are safe for an analyze, returning true. ``` =E2=80=9CThis function returns sets =E2=80=A6=E2=80=9D, is =E2=80=9Creturn= s=E2=80=9D a typo and not needed? 3 - 0002 ``` +-- Dummy function used for expression evaluations. +-- Note that this function does not use a function body on purpose, so = as +-- external statistics can be loaded from it. +CREATE OR REPLACE FUNCTION func_int_custom (p_value int_custom) + RETURNS int_custom LANGUAGE plpgsql AS $$ + BEGIN + RETURN p_value; + END; $$; ``` The comment says =E2=80=9Cthis function does not use a function body=E2=80= =9D, but the function has a body. This appears in two places. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/