* ExecInitRoutingInfo * Set up information needed for translating tuples between root * partitioned table format and partition format, and keep track of it * in PartitionTupleRouting. */
| 930 | * in PartitionTupleRouting. |
| 931 | */ |
| 932 | static void |
| 933 | ExecInitRoutingInfo(ModifyTableState *mtstate, |
| 934 | EState *estate, |
| 935 | PartitionTupleRouting *proute, |
| 936 | PartitionDispatch dispatch, |
| 937 | ResultRelInfo *partRelInfo, |
| 938 | int partidx, |
| 939 | bool is_borrowed_rel) |
| 940 | { |
| 941 | ResultRelInfo *rootRelInfo = partRelInfo->ri_RootResultRelInfo; |
| 942 | MemoryContext oldcxt; |
| 943 | int rri_index; |
| 944 | |
| 945 | oldcxt = MemoryContextSwitchTo(proute->memcxt); |
| 946 | |
| 947 | /* |
| 948 | * Set up a tuple conversion map to convert a tuple routed to the |
| 949 | * partition from the parent's type to the partition's. |
| 950 | */ |
| 951 | partRelInfo->ri_RootToPartitionMap = |
| 952 | convert_tuples_by_name(RelationGetDescr(rootRelInfo->ri_RelationDesc), |
| 953 | RelationGetDescr(partRelInfo->ri_RelationDesc)); |
| 954 | |
| 955 | /* |
| 956 | * If a partition has a different rowtype than the root parent, initialize |
| 957 | * a slot dedicated to storing this partition's tuples. The slot is used |
| 958 | * for various operations that are applied to tuples after routing, such |
| 959 | * as checking constraints. |
| 960 | */ |
| 961 | if (partRelInfo->ri_RootToPartitionMap != NULL) |
| 962 | { |
| 963 | Relation partrel = partRelInfo->ri_RelationDesc; |
| 964 | |
| 965 | /* |
| 966 | * Initialize the slot itself setting its descriptor to this |
| 967 | * partition's TupleDesc; TupleDesc reference will be released at the |
| 968 | * end of the command. |
| 969 | */ |
| 970 | partRelInfo->ri_PartitionTupleSlot = |
| 971 | table_slot_create(partrel, &estate->es_tupleTable); |
| 972 | } |
| 973 | else |
| 974 | partRelInfo->ri_PartitionTupleSlot = NULL; |
| 975 | |
| 976 | /* |
| 977 | * If the partition is a foreign table, let the FDW init itself for |
| 978 | * routing tuples to the partition. |
| 979 | */ |
| 980 | if (partRelInfo->ri_FdwRoutine != NULL && |
| 981 | partRelInfo->ri_FdwRoutine->BeginForeignInsert != NULL) |
| 982 | partRelInfo->ri_FdwRoutine->BeginForeignInsert(mtstate, partRelInfo); |
| 983 | |
| 984 | /* |
| 985 | * Determine if the FDW supports batch insert and determine the batch size |
| 986 | * (a FDW may support batching, but it may be disabled for the |
| 987 | * server/table or for this particular query). |
| 988 | * |
| 989 | * If the FDW does not support batching, we set the batch size to 1. |
no test coverage detected