| 1109 | } |
| 1110 | |
| 1111 | void |
| 1112 | ATExecGPPartCmds(Relation origrel, AlterTableCmd *cmd) |
| 1113 | { |
| 1114 | Relation rel = origrel; |
| 1115 | List *stmts = NIL; |
| 1116 | ListCell *l; |
| 1117 | |
| 1118 | while (cmd->subtype == AT_PartAlter) |
| 1119 | { |
| 1120 | GpAlterPartitionCmd *pc; |
| 1121 | GpAlterPartitionId *pid; |
| 1122 | Oid partrelid; |
| 1123 | |
| 1124 | pc = castNode(GpAlterPartitionCmd, cmd->def); |
| 1125 | pid = (GpAlterPartitionId *) pc->partid; |
| 1126 | cmd = (AlterTableCmd *) pc->arg; |
| 1127 | |
| 1128 | if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) |
| 1129 | { |
| 1130 | ereport(ERROR, |
| 1131 | (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), |
| 1132 | errmsg("table \"%s\" is not partitioned", |
| 1133 | RelationGetRelationName(rel)))); |
| 1134 | } |
| 1135 | |
| 1136 | partrelid = GpFindTargetPartition(rel, pid, false); |
| 1137 | Assert(OidIsValid(partrelid)); |
| 1138 | |
| 1139 | if (rel != origrel) |
| 1140 | table_close(rel, AccessShareLock); |
| 1141 | rel = table_open(partrelid, AccessShareLock); |
| 1142 | } |
| 1143 | |
| 1144 | /* |
| 1145 | * Most ALTER PARTITION commands are to ADD/DROP subpartitions, and don't |
| 1146 | * make sense unless the partition itself is a partitioned table. SET |
| 1147 | * DISTRIBUTED BY and SET TABLESPACE are exceptions. |
| 1148 | */ |
| 1149 | if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE && |
| 1150 | cmd->subtype != AT_SetDistributedBy && |
| 1151 | cmd->subtype != AT_SetTableSpace) |
| 1152 | { |
| 1153 | ereport(ERROR, |
| 1154 | (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), |
| 1155 | errmsg("table \"%s\" is not partitioned", |
| 1156 | RelationGetRelationName(rel)))); |
| 1157 | } |
| 1158 | |
| 1159 | switch (cmd->subtype) |
| 1160 | { |
| 1161 | case AT_PartTruncate: |
| 1162 | { |
| 1163 | GpAlterPartitionCmd *pc = castNode(GpAlterPartitionCmd, cmd->def); |
| 1164 | GpAlterPartitionId *pid = (GpAlterPartitionId *) pc->partid; |
| 1165 | TruncateStmt *truncstmt = (TruncateStmt *) pc->arg; |
| 1166 | Oid partrelid; |
| 1167 | RangeVar *rv; |
| 1168 | Relation partrel; |
no test coverage detected