aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 93f41ed1ffa..207197c4b3c 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16626,8 +16626,8 @@ AttachPartitionEnsureIndexes(Relation rel, Relation attachrel)
/*
* Scan the list of existing indexes in the partition-to-be, and mark
- * the first matching, unattached one we find, if any, as partition of
- * the parent index. If we find one, we're done.
+ * the first matching, valid, unattached one we find, if any, as
+ * partition of the parent index. If we find one, we're done.
*/
for (i = 0; i < list_length(attachRelIdxs); i++)
{
@@ -16638,6 +16638,10 @@ AttachPartitionEnsureIndexes(Relation rel, Relation attachrel)
if (attachrelIdxRels[i]->rd_rel->relispartition)
continue;
+ /* If this index is invalid, can't use it */
+ if (!attachrelIdxRels[i]->rd_index->indisvalid)
+ continue;
+
if (CompareIndexInfo(attachInfos[i], info,
attachrelIdxRels[i]->rd_indcollation,
idxRel->rd_indcollation,