* Return the address of the new parent relation. */
| 16887 | * Return the address of the new parent relation. |
| 16888 | */ |
| 16889 | static ObjectAddress |
| 16890 | ATExecAddInherit(Relation child_rel, RangeVar *parent, LOCKMODE lockmode) |
| 16891 | { |
| 16892 | Relation parent_rel; |
| 16893 | List *children; |
| 16894 | ObjectAddress address; |
| 16895 | const char *trigger_name; |
| 16896 | |
| 16897 | /* 1. Replicated table cannot inherit a parent */ |
| 16898 | if (child_rel->rd_cdbpolicy && |
| 16899 | child_rel->rd_cdbpolicy->ptype == POLICYTYPE_REPLICATED) |
| 16900 | ereport(ERROR, |
| 16901 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 16902 | errmsg("Replicated table cannot inherit a parent"))); |
| 16903 | |
| 16904 | /* |
| 16905 | * A self-exclusive lock is needed here. See the similar case in |
| 16906 | * MergeAttributes() for a full explanation. |
| 16907 | */ |
| 16908 | parent_rel = table_openrv(parent, ShareUpdateExclusiveLock); |
| 16909 | |
| 16910 | /* 2. Replicated table cannot be inherited */ |
| 16911 | if (parent_rel->rd_cdbpolicy && |
| 16912 | parent_rel->rd_cdbpolicy->ptype == POLICYTYPE_REPLICATED) |
| 16913 | ereport(ERROR, |
| 16914 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 16915 | errmsg("Replicated table cannot be inherited"))); |
| 16916 | |
| 16917 | /* |
| 16918 | * Must be owner of both parent and child -- child was checked by |
| 16919 | * ATSimplePermissions call in ATPrepCmd |
| 16920 | */ |
| 16921 | ATSimplePermissions(parent_rel, ATT_TABLE | ATT_FOREIGN_TABLE); |
| 16922 | |
| 16923 | /* Permanent rels cannot inherit from temporary ones */ |
| 16924 | if (parent_rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP && |
| 16925 | child_rel->rd_rel->relpersistence != RELPERSISTENCE_TEMP) |
| 16926 | ereport(ERROR, |
| 16927 | (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 16928 | errmsg("cannot inherit from temporary relation \"%s\"", |
| 16929 | RelationGetRelationName(parent_rel)))); |
| 16930 | /* If parent rel is temp, it must belong to this session */ |
| 16931 | if (parent_rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP && |
| 16932 | !parent_rel->rd_islocaltemp) |
| 16933 | ereport(ERROR, |
| 16934 | (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 16935 | errmsg("cannot inherit from temporary relation of another session"))); |
| 16936 | |
| 16937 | /* Ditto for the child */ |
| 16938 | if (child_rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP && |
| 16939 | !child_rel->rd_islocaltemp) |
| 16940 | ereport(ERROR, |
| 16941 | (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 16942 | errmsg("cannot inherit to temporary relation of another session"))); |
| 16943 | |
| 16944 | /* Prevent partitioned tables from becoming inheritance parents */ |
| 16945 | if (parent_rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) |
| 16946 | ereport(ERROR, |
no test coverage detected