* During DETACH PARTITION, verify that any foreign keys pointing to the * partitioned table would not become invalid. An error is raised if any * referenced values exist. */
| 23077 | * referenced values exist. |
| 23078 | */ |
| 23079 | static void |
| 23080 | ATDetachCheckNoForeignKeyRefs(Relation partition) |
| 23081 | { |
| 23082 | List *constraints; |
| 23083 | ListCell *cell; |
| 23084 | |
| 23085 | constraints = GetParentedForeignKeyRefs(partition); |
| 23086 | |
| 23087 | foreach(cell, constraints) |
| 23088 | { |
| 23089 | Oid constrOid = lfirst_oid(cell); |
| 23090 | HeapTuple tuple; |
| 23091 | Form_pg_constraint constrForm; |
| 23092 | Relation rel; |
| 23093 | Trigger trig; |
| 23094 | |
| 23095 | tuple = SearchSysCache1(CONSTROID, ObjectIdGetDatum(constrOid)); |
| 23096 | if (!HeapTupleIsValid(tuple)) |
| 23097 | elog(ERROR, "cache lookup failed for constraint %u", constrOid); |
| 23098 | constrForm = (Form_pg_constraint) GETSTRUCT(tuple); |
| 23099 | |
| 23100 | Assert(OidIsValid(constrForm->conparentid)); |
| 23101 | Assert(constrForm->confrelid == RelationGetRelid(partition)); |
| 23102 | |
| 23103 | /* prevent data changes into the referencing table until commit */ |
| 23104 | rel = table_open(constrForm->conrelid, ShareLock); |
| 23105 | |
| 23106 | MemSet(&trig, 0, sizeof(trig)); |
| 23107 | trig.tgoid = InvalidOid; |
| 23108 | trig.tgname = NameStr(constrForm->conname); |
| 23109 | trig.tgenabled = TRIGGER_FIRES_ON_ORIGIN; |
| 23110 | trig.tgisinternal = true; |
| 23111 | trig.tgconstrrelid = RelationGetRelid(partition); |
| 23112 | trig.tgconstrindid = constrForm->conindid; |
| 23113 | trig.tgconstraint = constrForm->oid; |
| 23114 | trig.tgdeferrable = false; |
| 23115 | trig.tginitdeferred = false; |
| 23116 | /* we needn't fill in remaining fields */ |
| 23117 | |
| 23118 | RI_PartitionRemove_Check(&trig, rel, partition); |
| 23119 | |
| 23120 | ReleaseSysCache(tuple); |
| 23121 | |
| 23122 | table_close(rel, NoLock); |
| 23123 | } |
| 23124 | } |
| 23125 | |
| 23126 | /* |
| 23127 | * resolve column compression specification to compression method. |
no test coverage detected