Re: Extended Statistics set/restore/clear functions.

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
Cc: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Tender Wang <tndrwang(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Extended Statistics set/restore/clear functions.
Date: 2026-01-28 02:46:04
Message-ID: aXl4bMfSTQUxM_yy@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2026-01-28 02:49:45 Re: tablecmds: fix bug where index rebuild loses replica identity on partitions
Previous Message Chao Li 2026-01-28 02:15:29 Re: tablecmds: reject CLUSTER ON for partitioned tables earlier