Re: ALTER TABLE: warn when actions do not recurse to partitions

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Greg Sabino Mullane <htamfids(at)gmail(dot)com>, Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: ALTER TABLE: warn when actions do not recurse to partitions
Date: 2026-01-22 05:45:05
Message-ID: CAEoWx2mZsWnyS_XLDL5mL+yuU_g65p_tmHNesyfngqow7gtS3A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Jan 14, 2026, at 08:52, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:

On Jan 13, 2026, at 19:16, Jim Jones <jim(dot)jones(at)uni-muenster(dot)de> wrote:

Hi Chao

On 13/01/2026 05:02, Chao Li wrote:

PSA v3:

* Rephrased the notice message as David's suggestion.
* Removed partition count from notice message.
* If a partitioned table doesn't have any partition, then suppress the
message.

I've been playing with this patch, and it seems to work as expected -
I'm surprised it didn't break any existing tests :). Do you plan to
extend this patch to other subcommands mentioned in your initial post,
such as SET STATISTICS?

Thanks for the patch

Best, Jim

Hi Jim,

Thanks for your testing. Yes, I plan to add the notice to other
sub-commands as needed. I only updated REPLICA IDENTITY first to call for
feedback. As you see, David has suggested the great wording for the notice
message. Once the change on REPLICA IDENTITY is reviewed, it’s easy to
extend to other sub-commands.

PFA v4.

I’ve extended the NOTICE to cover all sub-commands for which ONLY has no
effect and where actions on a partitioned table do not propagate to its
partitions:

- ALTER COLUMN SET/RESET attribute_option
- ALTER COLUMN SET COMPRESSION
- ENABLE/DISABLE RULE
- ENABLE/DISABLE/FORCE/NO FORCE ROW LEVEL SECURITY
- REPLICA IDENTITY
- OWNER TO
- SET TABLESPACE
- SET SCHEMA

RENAME is intentionally excluded. Using ONLY (or not) has no effect
for RENAME, since relation names are independent by nature and there is no
expectation of recursion.

OF / NOT OF are also excluded. Using ONLY has no effect for these commands,
as they apply only to the partitioned table itself and not to its
partitions.

One thing worth noting: following David’s suggestion, I removed the action
name from the NOTICE message in v2. However, I later realized that we do
need to include the action name, because an ALTER TABLE command may contain
multiple sub-commands, and the NOTICE would otherwise be ambiguous.

In v4, I reuse alter_table_type_to_string() to construct the action name,
consistent with what ATSimplePermissions() does. The NOTICE message itself
also follows the same style as messages emitted by ATSimplePermissions().
For example, when an ALTER TABLE contains multiple sub-commands, the output
now looks like:

```
evantest=# alter table p_test replica identity full, alter column username
set (n_distinct = 0.1);
NOTICE: ALTER action REPLICA IDENTITY on relation "p_test" does not affect
present partitions
HINT: partitions may be modified individually, or specify ONLY to suppress
this message
NOTICE: ALTER action ALTER COLUMN ... SET on relation "p_test" does not
affect present partitions
HINT: partitions may be modified individually, or specify ONLY to suppress
this message
ALTER TABLE
```

Regression tests have been updated, and a few new tests have been added. v4
should now be ready for review.

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

Attachment Content-Type Size
v4-0001-ALTER-TABLE-emit-NOTICE-when-ONLY-is-omitted-but-.patch application/octet-stream 32.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2026-01-22 05:45:54 Re: CREATE TABLE LIKE INCLUDING POLICIES
Previous Message Michael Paquier 2026-01-22 05:35:40 Re: Having problems generating a code coverage report