Re: Partitioned index marked valid while a partition is pending detach

From: shihao zhong <zhong950419(at)gmail(dot)com>
To: suryapoondla4(at)gmail(dot)com
Cc: michael(at)paquier(dot)xyz, alvherre(at)kurilemu(dot)de, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Partitioned index marked valid while a partition is pending detach
Date: 2026-11-11 01:20:32
Message-ID: CAGRkXqTg5JtwZQ+cf+caowb2e-nDLK++DkWyvZuY6tkDPYHKJg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Surya,

Thanks for testing each patch on its own. v4 is attached.

1. With only 0001 the index stays invalid after FINALIZE, which is safe. A
plain DETACH on master does the same, so I would fix that separately. I
don't think it blocks 0001 and 0002.

2. v4-0003 now lets ALTER TABLE on the parent reach p1, and the spec covers
it. pg_publication_tables leaves p1 out again, like pg_partition_tree().
This also fixes your DROP COLUMN case.

3. For the stable branches I would rather not refuse DDL. A table already
hit by this needs DDL on the parent to repair it, and that would be refused
too. But I am happy to go with what Michael and Alvaro prefer.

Thanks,
Shihao

On Mon, Nov 09, 2026 07:51 PM, surya poondla <suryapoondla4(at)gmail(dot)com>
wrote:

> Hi Shihao,
>
> Thanks for the findings and the patch.
> I tested all three v3 patches together, and 0001 by itself as this could
> be backported.
> make check and the isolation tests pass in both cases.
>
> With only 0001, if p1's index isn't attached yet, the parent index stays
> invalid even after FINALIZE:
>
> create table t (a int) partition by list (a);
> create table p1 partition of t for values in (1);
> create table p2 partition of t for values in (2);
> create unique index ti on only t (a);
> create unique index p1_a on p1 (a);
> create unique index p2_a on p2 (a);
> -- p1 pending detach
> alter index ti attach partition p2_a;
> alter index ti attach partition p1_a;
> ERROR: cannot attach index "p1_a" as a partition of index "ti"
> alter table t detach partition p1 finalize; -- ti still invalid
>
> ATExecAttachPartitionIdx() still skips p1, and FINALIZE doesn't
> revalidate.
> Re-attaching p2_a fixes it, but nobody would guess that.
> Maybe FINALIZE should revalidate the parent's indexes?
> Michael, this affects pushing 0001/0002 alone.
>
> As you noted, without 0003 FINALIZE fails after RENAME or ADD COLUMN
> on t, so that stays broken on the back branches. DROP COLUMN is worse as
> FINALIZE succeeds but p1 keeps the column as inherited:
>
> create table t (a int, b int) partition by list (a);
> create table p1 partition of t for values in (1);
> create table p2 partition of t for values in (2);
> -- p1 pending detach
> alter table t drop column b;
> alter table t detach partition p1 finalize;
> alter table p1 drop column b;
> ERROR: cannot drop inherited column "b"
> create table t9 (a int, b int) partition by list (a);
> alter table t9 attach partition p1 for values in (1);
> TRAP: failed Assert("child_att->attinhcount == 1")
>
> Alvaro's idea of rejecting DDL while a detach is pending looks like what
> the back branches need.
>
> With 0003, SET DEFAULT, SET STATISTICS and ALTER COLUMN TYPE on t now
> fail with "cannot alter partition "p1" with an incomplete detach", while
> ADD COLUMN etc. go through to p1. If that's intended, the spec
> should cover it. Also pg_publication_tables now lists p1 but
> pg_partition_tree() doesn't.
>
> Regards,
> Surya Poondla
>

Attachment Content-Type Size
v4-0001-Count-partitions-pending-detach-when-validating-a-pa.patch text/x-patch 1.2 KB
v4-0002-Test-partitioned-index-validity-while-a-partition-is.patch text/x-patch 4.3 KB
v4-0003-Let-DDL-see-partitions-pending-detach.patch text/x-patch 21.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2026-11-11 01:22:10 Re: Partitioned index marked valid while a partition is pending detach
Previous Message Fujii Masao 2026-11-11 01:09:35 Re: file_fdw: Fix ANALYZE does not enforce REJECT_LIMIT with on_error 'ignore'