* ALTER TABLE NO INHERIT * * Return value is the address of the relation that is no longer parent. */
| 17436 | * Return value is the address of the relation that is no longer parent. |
| 17437 | */ |
| 17438 | static ObjectAddress |
| 17439 | ATExecDropInherit(Relation rel, RangeVar *parent, LOCKMODE lockmode) |
| 17440 | { |
| 17441 | ObjectAddress address; |
| 17442 | Relation parent_rel; |
| 17443 | |
| 17444 | if (rel->rd_rel->relispartition) |
| 17445 | ereport(ERROR, |
| 17446 | (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 17447 | errmsg("cannot change inheritance of a partition"))); |
| 17448 | |
| 17449 | /* |
| 17450 | * AccessShareLock on the parent is probably enough, seeing that DROP |
| 17451 | * TABLE doesn't lock parent tables at all. We need some lock since we'll |
| 17452 | * be inspecting the parent's schema. |
| 17453 | */ |
| 17454 | parent_rel = table_openrv(parent, AccessShareLock); |
| 17455 | |
| 17456 | /* |
| 17457 | * We don't bother to check ownership of the parent table --- ownership of |
| 17458 | * the child is presumed enough rights. |
| 17459 | */ |
| 17460 | |
| 17461 | /* Off to RemoveInheritance() where most of the work happens */ |
| 17462 | RemoveInheritance(rel, parent_rel, false); |
| 17463 | |
| 17464 | ObjectAddressSet(address, RelationRelationId, |
| 17465 | RelationGetRelid(parent_rel)); |
| 17466 | |
| 17467 | /* keep our lock on the parent relation until commit */ |
| 17468 | table_close(parent_rel, NoLock); |
| 17469 | |
| 17470 | /* MPP-6929: metadata tracking */ |
| 17471 | if ((Gp_role == GP_ROLE_DISPATCH) |
| 17472 | && MetaTrackValidKindNsp(rel->rd_rel)) |
| 17473 | MetaTrackUpdObject(RelationRelationId, |
| 17474 | RelationGetRelid(rel), |
| 17475 | GetUserId(), |
| 17476 | "ALTER", "NO INHERIT" |
| 17477 | ); |
| 17478 | |
| 17479 | return address; |
| 17480 | } |
| 17481 | |
| 17482 | /* |
| 17483 | * MarkInheritDetached |
no test coverage detected