mirror of
https://github.com/postgres/postgres.git
synced 2025-11-24 00:23:06 +03:00
Change get_constraint_index() to use pg_constraint.conindid
It was still using a scan of pg_depend instead of using the conindid column that has been added since. Since it is now just a catalog lookup wrapper and not related to pg_depend, move from pg_depend.c to lsyscache.c. Reviewed-by: Matthias van de Meent <boekewurm+postgres@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://www.postgresql.org/message-id/flat/4688d55c-9a2e-9a5a-d166-5f24fe0bf8db%40enterprisedb.com
This commit is contained in:
@@ -968,75 +968,6 @@ getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok)
|
||||
return linitial_oid(seqlist);
|
||||
}
|
||||
|
||||
/*
|
||||
* get_constraint_index
|
||||
* Given the OID of a unique, primary-key, or exclusion constraint,
|
||||
* return the OID of the underlying index.
|
||||
*
|
||||
* Return InvalidOid if the index couldn't be found; this suggests the
|
||||
* given OID is bogus, but we leave it to caller to decide what to do.
|
||||
*/
|
||||
Oid
|
||||
get_constraint_index(Oid constraintId)
|
||||
{
|
||||
Oid indexId = InvalidOid;
|
||||
Relation depRel;
|
||||
ScanKeyData key[3];
|
||||
SysScanDesc scan;
|
||||
HeapTuple tup;
|
||||
|
||||
/* Search the dependency table for the dependent index */
|
||||
depRel = table_open(DependRelationId, AccessShareLock);
|
||||
|
||||
ScanKeyInit(&key[0],
|
||||
Anum_pg_depend_refclassid,
|
||||
BTEqualStrategyNumber, F_OIDEQ,
|
||||
ObjectIdGetDatum(ConstraintRelationId));
|
||||
ScanKeyInit(&key[1],
|
||||
Anum_pg_depend_refobjid,
|
||||
BTEqualStrategyNumber, F_OIDEQ,
|
||||
ObjectIdGetDatum(constraintId));
|
||||
ScanKeyInit(&key[2],
|
||||
Anum_pg_depend_refobjsubid,
|
||||
BTEqualStrategyNumber, F_INT4EQ,
|
||||
Int32GetDatum(0));
|
||||
|
||||
scan = systable_beginscan(depRel, DependReferenceIndexId, true,
|
||||
NULL, 3, key);
|
||||
|
||||
while (HeapTupleIsValid(tup = systable_getnext(scan)))
|
||||
{
|
||||
Form_pg_depend deprec = (Form_pg_depend) GETSTRUCT(tup);
|
||||
|
||||
/*
|
||||
* We assume any internal dependency of an index on the constraint
|
||||
* must be what we are looking for.
|
||||
*/
|
||||
if (deprec->classid == RelationRelationId &&
|
||||
deprec->objsubid == 0 &&
|
||||
deprec->deptype == DEPENDENCY_INTERNAL)
|
||||
{
|
||||
char relkind = get_rel_relkind(deprec->objid);
|
||||
|
||||
/*
|
||||
* This is pure paranoia; there shouldn't be any other relkinds
|
||||
* dependent on a constraint.
|
||||
*/
|
||||
if (relkind != RELKIND_INDEX &&
|
||||
relkind != RELKIND_PARTITIONED_INDEX)
|
||||
continue;
|
||||
|
||||
indexId = deprec->objid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
systable_endscan(scan);
|
||||
table_close(depRel, AccessShareLock);
|
||||
|
||||
return indexId;
|
||||
}
|
||||
|
||||
/*
|
||||
* get_index_constraint
|
||||
* Given the OID of an index, return the OID of the owning unique,
|
||||
|
||||
Reference in New Issue
Block a user