* Return an OID list of constraints that reference the given relation * that are marked as having a parent constraints. */
| 23024 | * that are marked as having a parent constraints. |
| 23025 | */ |
| 23026 | static List * |
| 23027 | GetParentedForeignKeyRefs(Relation partition) |
| 23028 | { |
| 23029 | Relation pg_constraint; |
| 23030 | HeapTuple tuple; |
| 23031 | SysScanDesc scan; |
| 23032 | ScanKeyData key[2]; |
| 23033 | List *constraints = NIL; |
| 23034 | |
| 23035 | /* |
| 23036 | * If no indexes, or no columns are referenceable by FKs, we can avoid the |
| 23037 | * scan. |
| 23038 | */ |
| 23039 | if (RelationGetIndexList(partition) == NIL || |
| 23040 | bms_is_empty(RelationGetIndexAttrBitmap(partition, |
| 23041 | INDEX_ATTR_BITMAP_KEY))) |
| 23042 | return NIL; |
| 23043 | |
| 23044 | /* Search for constraints referencing this table */ |
| 23045 | pg_constraint = table_open(ConstraintRelationId, AccessShareLock); |
| 23046 | ScanKeyInit(&key[0], |
| 23047 | Anum_pg_constraint_confrelid, BTEqualStrategyNumber, |
| 23048 | F_OIDEQ, ObjectIdGetDatum(RelationGetRelid(partition))); |
| 23049 | ScanKeyInit(&key[1], |
| 23050 | Anum_pg_constraint_contype, BTEqualStrategyNumber, |
| 23051 | F_CHAREQ, CharGetDatum(CONSTRAINT_FOREIGN)); |
| 23052 | |
| 23053 | /* XXX This is a seqscan, as we don't have a usable index */ |
| 23054 | scan = systable_beginscan(pg_constraint, InvalidOid, true, NULL, 2, key); |
| 23055 | while ((tuple = systable_getnext(scan)) != NULL) |
| 23056 | { |
| 23057 | Form_pg_constraint constrForm = (Form_pg_constraint) GETSTRUCT(tuple); |
| 23058 | |
| 23059 | /* |
| 23060 | * We only need to process constraints that are part of larger ones. |
| 23061 | */ |
| 23062 | if (!OidIsValid(constrForm->conparentid)) |
| 23063 | continue; |
| 23064 | |
| 23065 | constraints = lappend_oid(constraints, constrForm->oid); |
| 23066 | } |
| 23067 | |
| 23068 | systable_endscan(scan); |
| 23069 | table_close(pg_constraint, AccessShareLock); |
| 23070 | |
| 23071 | return constraints; |
| 23072 | } |
| 23073 | |
| 23074 | /* |
| 23075 | * During DETACH PARTITION, verify that any foreign keys pointing to the |
no test coverage detected