* ExecCleanupTupleRouting -- Clean up objects allocated for partition tuple * routing. * * Close all the partitioned tables, leaf partitions, and their indices. */
| 1186 | * Close all the partitioned tables, leaf partitions, and their indices. |
| 1187 | */ |
| 1188 | void |
| 1189 | ExecCleanupTupleRouting(ModifyTableState *mtstate, |
| 1190 | PartitionTupleRouting *proute) |
| 1191 | { |
| 1192 | int i; |
| 1193 | |
| 1194 | /* |
| 1195 | * Remember, proute->partition_dispatch_info[0] corresponds to the root |
| 1196 | * partitioned table, which we must not try to close, because it is the |
| 1197 | * main target table of the query that will be closed by callers such as |
| 1198 | * ExecEndPlan() or DoCopy(). Also, tupslot is NULL for the root |
| 1199 | * partitioned table. |
| 1200 | */ |
| 1201 | for (i = 1; i < proute->num_dispatch; i++) |
| 1202 | { |
| 1203 | PartitionDispatch pd = proute->partition_dispatch_info[i]; |
| 1204 | |
| 1205 | table_close(pd->reldesc, NoLock); |
| 1206 | |
| 1207 | if (pd->tupslot) |
| 1208 | ExecDropSingleTupleTableSlot(pd->tupslot); |
| 1209 | } |
| 1210 | |
| 1211 | for (i = 0; i < proute->num_partitions; i++) |
| 1212 | { |
| 1213 | ResultRelInfo *resultRelInfo = proute->partitions[i]; |
| 1214 | |
| 1215 | /* Allow any FDWs to shut down */ |
| 1216 | if (resultRelInfo->ri_FdwRoutine != NULL && |
| 1217 | resultRelInfo->ri_FdwRoutine->EndForeignInsert != NULL) |
| 1218 | resultRelInfo->ri_FdwRoutine->EndForeignInsert(mtstate->ps.state, |
| 1219 | resultRelInfo); |
| 1220 | |
| 1221 | /* |
| 1222 | * Close it if it's not one of the result relations borrowed from the |
| 1223 | * owning ModifyTableState; those will be closed by ExecEndPlan(). |
| 1224 | */ |
| 1225 | if (proute->is_borrowed_rel[i]) |
| 1226 | continue; |
| 1227 | |
| 1228 | /* |
| 1229 | * Only leaf node can have a valid access method. If we find an |
| 1230 | * appendoptimized table, ensure the DML operation is finished. |
| 1231 | */ |
| 1232 | table_dml_fini(resultRelInfo->ri_RelationDesc, mtstate->operation); |
| 1233 | |
| 1234 | ExecCloseIndices(resultRelInfo); |
| 1235 | table_close(resultRelInfo->ri_RelationDesc, NoLock); |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | /* ---------------- |
| 1240 | * FormPartitionKeyDatum |
no test coverage detected