Re: Proposal: Cascade REPLICA IDENTITY changes to leaf partitions - Mailing list pgsql-hackers

From Chao Li
Subject Re: Proposal: Cascade REPLICA IDENTITY changes to leaf partitions
Date
Msg-id 99E57FD0-29B0-4477-99A6-13F8B404B227@gmail.com
Whole thread Raw
In response to Re: Proposal: Cascade REPLICA IDENTITY changes to leaf partitions  (Chao Li <li.evan.chao@gmail.com>)
List pgsql-hackers

> On Dec 18, 2025, at 12:21, Chao Li <li.evan.chao@gmail.com> wrote:
>
>>
>> 2) Should we simply use the ONLY keyword to determine whether to propagate the
>> replica identity to partitions instead of adding [NOT] INHERIT? For example, if
>> a user specifies ONLY, it changes the identity of the parent table, and any
>> newly created partitions will adopt this new identity. However, the identities
>> of existing partitions remain unchanged.
>
> The current syntax “ALTER TABLE [ONLY] table_name action”, I think here “ONLY” works in terms of inherited tables but
partitions.(I surprisedly find the doc doesn’t explain “ONLY” at all.) The current behavior (without my patch) proves
myunderstanding, “ALTER TABLE table_name REPLICA IDENTITY” only updates the parent table itself. 
>
> Given that it is not allowed to inherit a table from either a partitioned table (root/parent) or partition (leaf),
reusingthe “ONLY" at “ALTER TABLE” level won’t generate a conflict. But the problem is, we will have to revisit all
ALTERTABLE actions to see if they can propagate to partitions when the target table is a partitioned table. In that
case,scope of this patch is extremely extended. 
>
> The current approach adding INHERIT to the action “REPLICA IDENTIFY” has no global impacts. If you look at the patch,
thesyntax this patch uses is: 
> ```
> ALTER TABLE ...
> REPLICA IDENTITY { DEFAULT [ INHERIT | NO INHERIT ] |
>                    USING INDEX index_name |
>                    FULL [ INHERIT | NO INHERIT ] |
>                    NOTHING [ INHERIT | NO INHERIT ] }
> ```
> It explicitly avoids the complexity of “USING INDEX”, thus we don’t have to mention any exceptions in docs.
>
> Amit, what do you think?

I read through the doc of “ALTER TABLE” again, and got some findings.

```
name - The name (optionally schema-qualified) of an existing table to alter. If ONLY is specified before the table
name,only that table is altered. If ONLY is not specified, the table and all its descendant tables (if any) are
altered.Optionally, * can be specified after the table name to explicitly indicate that descendant tables are included. 
```

For table name, it says "If ONLY is specified before the table name, only that table is altered. If ONLY is not
specified,the table and all its descendant tables (if any) are altered.” Here, I think we can “descendant tables” as
bothinherited table or partition table, as they are mutually exclusive. 

And for “DISABLE/ENABLE [ REPLICA | ALWAYS ] TRIGGER”, the doc says:
```
DISABLE/ENABLE [ REPLICA | ALWAYS ] TRIGGER

When this command is applied to a partitioned table, the states of corresponding clone triggers in the partitions are
updatedtoo, unless ONLY is specified. 
```

Here, ONLY is used for partition table. From this perspective, “REPLICA IDENTITY” not propagating to children feels
likea “bug”. 

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







pgsql-hackers by date:

Previous
From: VASUKI M
Date:
Subject: Re: Custom oauth validator options
Next
From: Michael Paquier
Date:
Subject: Re: Support for 8-byte TOAST values (aka the TOAST infinite loop problem)