From a90327a1ed87e83c9f48cf00ca6610184f56d561 Mon Sep 17 00:00:00 2001
From: Mohamed Ali <moali.pg@gmail.com>
Date: Fri, 15 May 2026 11:12:53 -0700
Subject: [PATCH v2] doc: Document that invalid indexes are skipped during
 ATTACH PARTITION

When ALTER TABLE ... ATTACH PARTITION matches partition indexes to the
parent table's indexes, invalid indexes (e.g., from a failed CREATE
INDEX CONCURRENTLY) are skipped.  This behavior was added by commit
e90e9275f56 but never documented.

Rewrite the index-matching sentence to clarify that only valid
equivalent indexes are considered for attachment, and that a new index
is created otherwise.  Also note that any pre-existing invalid indexes
remain unchanged and should be dropped manually.

Discussion: https://www.postgresql.org/message-id/CAGnOmWpAMaE-BOkpwM6mJnHcpS2QZ8yLSSaqmz%2BvryEsbCWWWA%40mail.gmail.com
---
 doc/src/sgml/ref/alter_table.sgml | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 1f9a456fd33..54e25419f02 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1054,10 +1054,13 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       as a partition of the target table. The table can be attached
       as a partition for specific values using <literal>FOR VALUES</literal>
       or as a default partition by using <literal>DEFAULT</literal>.
-      For each index in the target table, a corresponding
-      one will be created in the attached table; or, if an equivalent
-      index already exists, it will be attached to the target table's index,
-      as if <command>ALTER INDEX ATTACH PARTITION</command> had been executed.
+      For each index in the target table, if a valid equivalent
+      index already exists in the partition, it will be attached
+      to the target table's index, as if <command>ALTER INDEX ATTACH
+      PARTITION</command> had been executed; otherwise, a corresponding
+      one will be created.  Any invalid indexes on the partition remain
+      unchanged and should be dropped manually if they are no longer
+      needed.
       Note that if the existing table is a foreign table, it is currently not
       allowed to attach the table as a partition of the target table if there
       are <literal>UNIQUE</literal> indexes on the target table.  (See also
-- 
2.50.1 (Apple Git-155)

