* Obtain list of partitions of the given table, locking them all at the given * lockmode and ensuring that they all pass CheckTableNotInUse. * * This function is a no-op if the given relation is not a partitioned table; * in particular, nothing is done if it's a legacy inheritance parent. */
| 7992 | * in particular, nothing is done if it's a legacy inheritance parent. |
| 7993 | */ |
| 7994 | static void |
| 7995 | ATCheckPartitionsNotInUse(Relation rel, LOCKMODE lockmode) |
| 7996 | { |
| 7997 | if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) |
| 7998 | { |
| 7999 | List *inh; |
| 8000 | ListCell *cell; |
| 8001 | |
| 8002 | inh = find_all_inheritors(RelationGetRelid(rel), lockmode, NULL); |
| 8003 | /* first element is the parent rel; must ignore it */ |
| 8004 | for_each_from(cell, inh, 1) |
| 8005 | { |
| 8006 | Relation childrel; |
| 8007 | |
| 8008 | /* find_all_inheritors already got lock */ |
| 8009 | childrel = table_open(lfirst_oid(cell), NoLock); |
| 8010 | CheckTableNotInUse(childrel, "ALTER TABLE"); |
| 8011 | table_close(childrel, NoLock); |
| 8012 | } |
| 8013 | list_free(inh); |
| 8014 | } |
| 8015 | } |
| 8016 | |
| 8017 | /* |
| 8018 | * ATTypedTableRecursion |
no test coverage detected