Re: misleading error message in ProcessUtilitySlow T_CreateStatsStmt

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Cc: Peter Eisentraut <peter(at)eisentraut(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Kirill Reshke <reshkekirill(at)gmail(dot)com>
Subject: Re: misleading error message in ProcessUtilitySlow T_CreateStatsStmt
Date: 2025-12-17 05:49:36
Message-ID: CACJufxEs=DxDZ07xbUW_tYqJhdnoNf84UC1LzY6g+E58t19p3Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Nov 13, 2025 at 5:41 PM Álvaro Herrera <alvherre(at)kurilemu(dot)de> wrote:
>

>
> > @@ -15658,10 +15658,19 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd,
> > querytree_list = list_concat(querytree_list, afterStmts);
> > }
> > else if (IsA(stmt, CreateStatsStmt))
> > + {
> > + RangeTblEntry *rte;
> > + CreateStatsStmt *ss = castNode(CreateStatsStmt, stmt);
> > +
> > + rte = makeNode(RangeTblEntry);
> > + rte->rtekind = RTE_RELATION;
> > + rte->relid = oldRelId;
> > + rte->rellockmode = ShareUpdateExclusiveLock;
> > + ss->rtable = list_make1(rte);
> > +
> > querytree_list = lappend(querytree_list,
> > - transformStatsStmt(oldRelId,
> > - (CreateStatsStmt *) stmt,
> > - cmd));
> > + transformStatsStmt(ss, cmd));
> > + }
> > else
> > querytree_list = lappend(querytree_list, stmt);
> > }
>
> Hmm, how would this part here work in the hypothetical world where a
> stats object references multiple relations?
>
hi.

For extended statistics that span multiple relations (hypothetically),
we should have the OIDs of
all involved relations within the pg_statistic_ext catalog. Without this , it's
hard to do statistic's expression deparse, changing column data types
or generation
expressions. Catalog pg_depend do have statistics associated relation OIDs
information, relying on it for statistical expression deparsing would be more
complicated.

Once pg_statistic_ext have all relation oid information,
RememberStatisticsForRebuilding will not only collecting
AlteredTableInfo->changedStatisticsOids, it will aslo collect the OID of other
relations associated with this statistic.

For the above quoted part, we should construct a RangeTblEntry for
each associated
relation (OID).
Obviously transformStatsStmt itself needs to figure out how to
deal with multi-relation expressions.

rebased and minor polishing.

--
jian
https://www.enterprisedb.com

Attachment Content-Type Size
v6-0001-Restructure-CreateStatsStmt-parse-analysis-processing.patch text/x-patch 17.2 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Soumya S Murali 2025-12-17 05:53:08 Re: Checkpointer write combining
Previous Message Ashutosh Bapat 2025-12-17 05:32:30 Re: SQL Property Graph Queries (SQL/PGQ)