pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Corey Huinker <corey.huinker@gmail.com>
Cc: Chao Li <li.evan.chao@gmail.com>
Cc: Tender Wang <tndrwang@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Extended Statistics set/restore/clear functions.
Date: Wed, 28 Jan 2026 11:46:04 +0900
Message-ID: <aXl4bMfSTQUxM_yy@paquier.xyz> (raw)
In-Reply-To: <aXlPml6eaoU8lM5f@paquier.xyz>
References: <CADkLM=c3JivzHNXLt-X_JicYknRYwLTiOCHOPiKagm2_vdrFUg@mail.gmail.com>
	<aXVw4LGO4fWunn4n@paquier.xyz>
	<CADkLM=f4+3_HrXSAaEic5VGGd-fOjS4jGnr1WGJYrL7vf3ZJnw@mail.gmail.com>
	<aXWBhkru03FnrfIW@paquier.xyz>
	<CADkLM=c7DY3Jv6ef0n_MGUJ1FyTMUoT697LbkST05nraVGNHYg@mail.gmail.com>
	<aXca7jnwtzFSYr4s@paquier.xyz>
	<aXhFKleXWlooHcy3@paquier.xyz>
	<CADkLM=dZr_Ut3jKw94_BisyyDtNZPRJWeOALXVzcJz=ZFTAhvQ@mail.gmail.com>
	<CADkLM=fTgxGL+pcw7RFHe3EP+rmc-Dk_pwh-HWJkonF+xDPqMQ@mail.gmail.com>
	<aXlPml6eaoU8lM5f@paquier.xyz>

On Wed, Jan 28, 2026 at 08:51:54AM +0900, Michael Paquier wrote:
> On Tue, Jan 27, 2026 at 11:14:12AM -0500, Corey Huinker wrote:
> >> 0001 - adds a test left out of dependencies
> 
> Applied this one now, you are right that it should have been added in
> 302879bd68d1, so my mistake I guess.

This code in v32-0002 has given me a pause, because we define numexprs
and use it down the road for some input validation:
+    /* decode expression (if any) */
+    exprdatum = SysCacheGetAttr(STATEXTOID,
+                                tup,
+                                Anum_pg_statistic_ext_stxexprs,
+                                &isnull);
+
+    if (!isnull)
+    {
[...]
+    }
+    numexprs = list_length(exprs);

Actually, I think that the patch split has been done incorrectly
because missing this code on HEAD also means that we do not perform a 
correct validation of ndistinct and dependencies data when any of
these include expressions, because we are missing the negative
attribute numbers, numexprs remaining at 0 all the time.  This can be
easily demonstrated with a statext object like that;
CREATE STATISTICS stats_obj (dependencies) ON lower(name), upper(name)
  FROM tab_obj;

The restore function would reject input like that, but it should be
valid:
[{"attributes": [-1], "dependency": -2, "degree": 1.000000},
 {"attributes": [-2], "dependency": -1, "degree": 1.000000}]

I'll go fix that now with some tests to cover things, after extracting
the relevant portion of the code from v32-0002.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (141+ messages)  latest in thread

Message-ID: <aXl4bMfSTQUxM_yy@paquier.xyz>
Permalink:  ../aXl4bMfSTQUxM_yy@paquier.xyz/
Also on:    postgresql.org/message-id/aXl4bMfSTQUxM_yy@paquier.xyz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: michael@paquier.xyz, corey.huinker@gmail.com, li.evan.chao@gmail.com, tndrwang@gmail.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: Extended Statistics set/restore/clear functions.
  In-Reply-To: <aXl4bMfSTQUxM_yy@paquier.xyz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox