ALTER TABLE: warn when actions do not recurse to partitions - Mailing list pgsql-hackers

From Chao Li
Subject ALTER TABLE: warn when actions do not recurse to partitions
Date
Msg-id CAEoWx2=SLga-xH09Cq_PAvsHhQHrBK+V0vF821JKgzS=Bm0haA@mail.gmail.com
Whole thread Raw
Responses Re: ALTER TABLE: warn when actions do not recurse to partitions
List pgsql-hackers
Hi Hacker,

This patch is part of a broader effort to make ALTER TABLE actions behave more consistently with respect to partitioned tables. There has been ongoing discussion around this area; see [1], which also links to earlier related threads.

In short, changing ALTER TABLE semantics requires more discussion and coordination than a single patch can realistically achieve. Before that larger work happens, I’m following up on [1] by trying to clarify the current behavior, both in documentation and in user-facing feedback.

This patch adds warning messages for sub-commands that appear to recurse but in fact do not. These currently include:

* SET STATISTICS
* SET/RESET (attribute_option = value)
* ENABLE/DISABLE [ REPLICA | ALWAYS] RULE
* ENABLE/DISABLE ROW LEVEL SECURITY
* NO FORCE / FORCE ROW LEVEL SECURITY
* OWNER TO
* REPLICA IDENTITY
* SET SCHEMA

For example, if a user runs:
```
ALTER TABLE ONLY a_partitioned_table REPLICA IDENTITY FULL;
```
the semantics are clear: only the partitioned table itself is modified.

However, if the user runs the same command without ONLY:
```
ALTER TABLE a_partitioned_table REPLICA IDENTITY FULL;
```
there is potential confusion. From the command syntax alone, it is reasonable to assume that the change would propagate to child partitions, but in reality, it does not. Since the ALTER TABLE documentation does not explicitly spell this out, users often need to test the behavior themselves to be sure, which is a poor user experience.

With this patch, the command instead emits a warning such as:
```
evantest=# alter table sensor_data replica identity full;
WARNING:  REPLICA IDENTITY is only applied to the partitioned table itself
ALTER TABLE
```
This makes the behavior explicit and removes the ambiguity.

For now, I’ve limited the change to REPLICA IDENTITY to see whether there are objections to this approach. If there are none, I plan to extend the same warning behavior to the other sub-commands listed above. After that, users can reasonably assume that an ALTER TABLE partitioned_table ... action will recurse to child partitions unless a warning explicitly tells them otherwise.


Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/




Attachment

pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: [Proposal] Adding Log File Capability to pg_createsubscriber
Next
From: Konstantin Knizhnik
Date:
Subject: Re: global temporary table (GTT) - are there some ideas how to implement it?