Re: tablecmds: fix bug where index rebuild loses replica identity on partitions

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: tablecmds: fix bug where index rebuild loses replica identity on partitions
Date: 2026-01-27 07:39:36
Message-ID: aXhruFBS8ZZgKolq@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jan 27, 2026 at 01:13:32PM +0800, Chao Li wrote:
> I found this bug while working on a related patch [1].
>
> When ALTER TABLE ... ALTER COLUMN TYPE causes an index rebuild, and
> that index is used as REPLICA IDENTITY on a partitioned table, the
> replica identity marking on partitions can be silently lost after the
> rebuild.

I am slightly confused by the tests included in the proposed patch.
On HEAD, if I undo the proposed changes of tablecmds.c, the tests
pass. If I run the tests of the patch with the changes of
tablecmds.c, the tests also pass. These tests don't check what you
want them to.

- if (tab->replicaIdentityIndex)
+ if (tab->replicaIdentityIndexOids != NIL)
elog(ERROR, "relation %u has multiple indexes marked as replica identity", tab->relid);

This looks wrong to me. This new list tracks the OIDs of indexes
where you'd want to make sure that relreplident is updated, and it
could be possible, based on your proposal, that multiple indexes are
stored in this list. The error message is at least not in line
anymore. Actually, do we really need this extra list at all? The
list of indexes to rebuild are tracked already in changedIndexOids,
and the partitioned indexes seem to be in it, no?
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2026-01-27 07:48:27 Re: tablecmds: reject CLUSTER ON for partitioned tables earlier
Previous Message ywgrit 2026-01-27 07:33:06 Re: Some questions about JIT optimization