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

From: Sami Imseih <samimseih(dot)pg(at)gmail(dot)com>
To: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>
Subject: Re: tablecmds: fix bug where index rebuild loses replica identity on partitions
Date: 2026-09-05 16:44:17
Message-ID: CAN12+YJbTMimpF3y3duLcb9_gqrTkXd_Q81KmQPL4Ep3ptCb5g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> create schema w1; set search_path = w1;
> create table p (id int not null, a int not null) partition by list (id);
> create table p1 partition of p for values in (1);
> create table p2 partition of p for values in (2);
> create index p_idx on only p (a); -- invalid parent: nothing attached
> create index tmp on p2 (a);
> alter index p_idx attach partition tmp; -- p2 attached, p1 still not
> alter index tmp rename to p1_a_idx; -- p2's index holds p1's default name
> alter table p alter column a type bigint; -- ERROR: relation
> "p1_a_idx" already exists; should work

Nice find! This is not v18 specific and has existed since we started
preserving index names.

The main issue here is the name clash during partition index rebuild.
Checking pg_class alone is not sufficient, because that only sees names
that currently exist in the catalogs. In this case we also have names from
the old descendant index hierarchy that have already been captured and are
effectively reserved by the current command, even though they are not
visible in pg_class yet.

So, v19 follows the existing pg_constraint pattern and tracks the
names reserved
during the command. When we need to auto-generate a replacement child index
name, we check both the catalog and the reserved names list.

I added a test case for this also.

> Also, with the additional split 0003 now deletes a test case added by
> 0001, is that intentional?

That was my splitting of patches mistake. Fixed.

--
Sami Imseih
Amazon Web Services (AWS)

Attachment Content-Type Size
v19-0001-Preserve-index-DEPENDS-ON-EXTENSION-across-ALTER.patch application/octet-stream 6.9 KB
v19-0002-Preserve-index-per-column-statistics-targets-acr.patch application/octet-stream 13.6 KB
v19-0003-Preserve-descendant-partition-index-properties-a.patch application/octet-stream 48.2 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Rui Zhao 2026-09-05 16:44:56 Re: hashjoins vs. Bloom filters (yet again)
Previous Message Andrey Borodin 2026-09-05 15:05:04 Re: Commitfest manager for September 2026