Re: misleading error message in ProcessUtilitySlow T_CreateStatsStmt

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Álvaro Herrera <alvherre(at)kurilemu(dot)de>, 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-08-29 04:07:24
Message-ID: CACJufxFcvo=fM6J9RC88n1U=eS9+5QdftwUNQMu5h7OgjmqDwQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Aug 29, 2025 at 5:46 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> =?utf-8?Q?=C3=81lvaro?= Herrera <alvherre(at)kurilemu(dot)de> writes:
> > I propose to use this report:
>
> > ERROR: cannot create statistics on specified relation
> > DETAIL: CREATE STATISTICS only supports tables, materialized views, foreign tables, and partitioned tables.
>
> WFM, although I think you could shorten it to "tables, materialized
> views, and foreign tables". We generally expect that partitioned
> tables are included when saying "tables", no? I'm not dead set on
> that either way, though.
>

https://www.postgresql.org/docs/current/sql-copy.html
use "COPY TO can be used only with plain tables, not views, and does
not copy rows from child tables or child partitions"

>
> Alternatively, maybe the right fix is to move the parse-analysis
> work into CreateStatistics altogether. I think there is not a
> very good argument for ProcessUtilitySlow doing all that stuff.
> It's supposed to mainly just be a dispatching switch(), IMO.
>
seems doable.
transformStatsStmt, CreateStatistics both used only twice, refactoring arguments
should be fine.
please check the attached POC, regress tests also added.

main idea is
first check CreateStatsStmt->relations,
then call transformStatsStmt, transformStatsStmt only to transform
CreateStatsStmt->exprs.
also the above complaint about the relation lock issue will be resolved.

Attachment Content-Type Size
v2-0001-refactor-CreateStatsStmt.patch text/x-patch 8.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2025-08-29 04:07:41 Re: POC: enable logical decoding when wal_level = 'replica' without a server restart
Previous Message Amit Kapila 2025-08-29 04:05:23 Re: Avoid retaining conflict-related data when no tables are subscribed