ALTER TABLE ... SET DATA TYPE removes statistics

From: "nikolai(dot)berkoff" <nikolai(dot)berkoff(at)pm(dot)me>
To: "pgsql-docs(at)lists(dot)postgresql(dot)org" <pgsql-docs(at)lists(dot)postgresql(dot)org>
Subject: ALTER TABLE ... SET DATA TYPE removes statistics
Date: 2021-10-08 09:03:34
Message-ID: vCc8XnwDmlP4ZnHBQLIVxzD405BiYHVC9qZlhIF7IsfxK0gC9mZ4PUUOH0-3y6kv5p-87-3_ljqT1KvQVAnb8OoWhPU3kcqWn2ZpmxRBCQg=@pm.me
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
set_data_type.patch text/x-patch 907 bytes

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message nikolai.berkoff 2021-10-08 09:33:51 vacuumdb --analyze-in-stages
Previous Message Anitha P 2021-10-08 07:36:22 Fwd: PostgreSQL 12 Authentication type questions