Re: Doc: Add note for running ANALYZE after ALTER TABLE ... SET EXPRESSION

From: Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Doc: Add note for running ANALYZE after ALTER TABLE ... SET EXPRESSION
Date: 2025-08-05 01:09:06
Message-ID: 20250805100906.93f5020653328becae39091a@sraoss.co.jp
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 4 Aug 2025 20:01:34 +0900
Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:

> On Mon, Aug 4, 2025 at 3:14 PM Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp> wrote:
> >
> > Hi,
> >
> > The documentation recommends running ANALYZE after the "ALTER TABLE ... SET DATA TYPE"
> > command since the statistics will become wrong after that.
> >
> > That same thing can be applied to "ALTER TABLE ... SET EXPRESSION" commands,
> > but that is not described in the documentation, so I've attached a patch
> > to add this statement.
>
> +1
>
> + When this form is used, the column's statistics are removed,
> + so running <link linkend="sql-analyze"><command>ANALYZE</command></link>
> + on the table afterwards is recommended.
>
> ANALYZE is not needed for virtual generated columns, since they
> don't have statistics in the first place? If so, would it be clearer to
> explicitly mention that? How about rephrasing it like this?
>
> ------------------------------
> When this form is used on a stored generated column, its statistics
> are removed, so running <link linkend="sql-analyze"><command>ANALYZE
> </command></link> on the table afterwards is recommended.
> For a virtual generated column, <command>ANALYZE</command>
> is not necessary because such columns never have statistics.
> ------------------------------

Thank you for looking at it. I overlooked that virtual generated columns
don't have statistics currently (I'm working on this at [1], though).

Your suggestion makes sense, so I've attached an updated patch.
I also mentioned virtual generated column in the description
of SET DATA TYPE.

[1] https://www.postgresql.org/message-id/20250801002830.143b25971fb9594b89d96aee%40sraoss.co.jp

Regards,
Yugo Nagata

--
Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>

Attachment Content-Type Size
v2_fix_doc_alter_table_set_expression.patch text/x-diff 1.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Erik Wienhold 2025-08-05 01:17:06 Re: CREATE OR REPLACE MATERIALIZED VIEW
Previous Message Xuneng Zhou 2025-08-05 00:14:37 Re: Bug in pg_dump --filter? - Invalid object types can be misinterpreted as valid