mirror of
https://github.com/postgres/postgres.git
synced 2025-06-22 02:52:08 +03:00
Fix partitioned index attachment
When an existing index in a partition is attached to a new index on its parent, we forgot to set the "relispartition" flag correctly, which meant that it was not possible to find the index in various operations, such as adding a foreign key constraint that references that partitioned table. One of four places that was assigning the parent index was forgetting to do that, so fix by shifting responsibility of updating the flag to the routine that changes the parent. Author: Amit Langote, Álvaro Herrera Reported-by: Hubert "depesz" Lubaczewski Discussion: https://postgr.es/m/CA+HiwqHMsRtRYRWYTWavKJ8x14AFsv7bmAV46mYwnfD3vy8goQ@mail.gmail.com
This commit is contained in:
@ -89,6 +89,7 @@ static void RangeVarCallbackForReindexIndex(const RangeVar *relation,
|
||||
Oid relId, Oid oldRelId, void *arg);
|
||||
static bool ReindexRelationConcurrently(Oid relationOid, int options);
|
||||
static void ReindexPartitionedIndex(Relation parentIdx);
|
||||
static void update_relispartition(Oid relationId, bool newval);
|
||||
|
||||
/*
|
||||
* CheckIndexCompatible
|
||||
@ -3388,6 +3389,9 @@ IndexSetParentIndex(Relation partitionIdx, Oid parentOid)
|
||||
if (OidIsValid(parentOid))
|
||||
SetRelationHasSubclass(parentOid, true);
|
||||
|
||||
/* set relispartition correctly on the partition */
|
||||
update_relispartition(partRelid, OidIsValid(parentOid));
|
||||
|
||||
if (fix_dependencies)
|
||||
{
|
||||
/*
|
||||
@ -3424,3 +3428,23 @@ IndexSetParentIndex(Relation partitionIdx, Oid parentOid)
|
||||
CommandCounterIncrement();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Subroutine of IndexSetParentIndex to update the relispartition flag of the
|
||||
* given index to the given value.
|
||||
*/
|
||||
static void
|
||||
update_relispartition(Oid relationId, bool newval)
|
||||
{
|
||||
HeapTuple tup;
|
||||
Relation classRel;
|
||||
|
||||
classRel = table_open(RelationRelationId, RowExclusiveLock);
|
||||
tup = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(relationId));
|
||||
Assert(((Form_pg_class) GETSTRUCT(tup))->relispartition != newval);
|
||||
((Form_pg_class) GETSTRUCT(tup))->relispartition = newval;
|
||||
CatalogTupleUpdate(classRel, &tup->t_self, tup);
|
||||
heap_freetuple(tup);
|
||||
|
||||
table_close(classRel, RowExclusiveLock);
|
||||
}
|
||||
|
Reference in New Issue
Block a user