ALTER TABLE ... SET DATA TYPE removes statistics - Mailing list pgsql-docs

From nikolai.berkoff
Subject ALTER TABLE ... SET DATA TYPE removes statistics
Date
Msg-id vCc8XnwDmlP4ZnHBQLIVxzD405BiYHVC9qZlhIF7IsfxK0gC9mZ4PUUOH0-3y6kv5p-87-3_ljqT1KvQVAnb8OoWhPU3kcqWn2ZpmxRBCQg=@pm.me
Whole thread Raw
Responses Re: ALTER TABLE ... SET DATA TYPE removes statistics  ("Euler Taveira" <euler@eulerto.com>)
List pgsql-docs
The current documentation does not mention that the column statistics are removed which I can see they are in
src/backend/commands/tablecmds.c

ATExecAlterColumnType
    /*
     * Drop any pg_statistic entry for the column, since it's now wrong type
     */
    RemoveStatistics(RelationGetRelid(rel), attnum);

Although this might be obvious it tripped me up.  For example renaming and SET STATISTICS preserves statistics.  Patch
attached.

Regards,

Nikolai
Attachment

pgsql-docs by date:

Previous
From: Anitha P
Date:
Subject: Fwd: PostgreSQL 12 Authentication type questions
Next
From: "nikolai.berkoff"
Date:
Subject: vacuumdb --analyze-in-stages