mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-28 11:55:03 +03:00 
			
		
		
		
	Revise child-to-root tuple conversion map management.
Store the tuple conversion map to convert a tuple from a child table's format to the root format in a new ri_ChildToRootMap field in ResultRelInfo. It is initialized if transition tuple capture for FOR STATEMENT triggers or INSERT tuple routing on a partitioned table is needed. Previously, ModifyTable kept the maps in the per-subplan ModifyTableState->mt_per_subplan_tupconv_maps array, or when tuple routing was used, in ResultRelInfo->ri_Partitioninfo->pi_PartitionToRootMap. The new field replaces both of those. Now that the child-to-root tuple conversion map is always available in ResultRelInfo (when needed), remove the TransitionCaptureState.tcs_map field. The callers of Exec*Trigger() functions no longer need to set or save it, which is much less confusing and bug-prone. Also, as a future optimization, this will allow us to delay creating the map for a given result relation until the relation is actually processed during execution. Author: Amit Langote Discussion: https://www.postgresql.org/message-id/CA%2BHiwqHtCWLdK-LO%3DNEsvOdHx%2B7yv4mE_zYK0i3BH7dXb-wxog%40mail.gmail.com
This commit is contained in:
		| @@ -3106,31 +3106,14 @@ CopyFrom(CopyState cstate) | ||||
|  | ||||
| 			/* | ||||
| 			 * If we're capturing transition tuples, we might need to convert | ||||
| 			 * from the partition rowtype to root rowtype. | ||||
| 			 * from the partition rowtype to root rowtype. But if there are no | ||||
| 			 * BEFORE triggers on the partition that could change the tuple, | ||||
| 			 * we can just remember the original unconverted tuple to avoid a | ||||
| 			 * needless round trip conversion. | ||||
| 			 */ | ||||
| 			if (cstate->transition_capture != NULL) | ||||
| 			{ | ||||
| 				if (has_before_insert_row_trig) | ||||
| 				{ | ||||
| 					/* | ||||
| 					 * If there are any BEFORE triggers on the partition, | ||||
| 					 * we'll have to be ready to convert their result back to | ||||
| 					 * tuplestore format. | ||||
| 					 */ | ||||
| 					cstate->transition_capture->tcs_original_insert_tuple = NULL; | ||||
| 					cstate->transition_capture->tcs_map = | ||||
| 						resultRelInfo->ri_PartitionInfo->pi_PartitionToRootMap; | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| 					/* | ||||
| 					 * Otherwise, just remember the original unconverted | ||||
| 					 * tuple, to avoid a needless round trip conversion. | ||||
| 					 */ | ||||
| 					cstate->transition_capture->tcs_original_insert_tuple = myslot; | ||||
| 					cstate->transition_capture->tcs_map = NULL; | ||||
| 				} | ||||
| 			} | ||||
| 				cstate->transition_capture->tcs_original_insert_tuple = | ||||
| 					!has_before_insert_row_trig ? myslot : NULL; | ||||
|  | ||||
| 			/* | ||||
| 			 * We might need to convert from the root rowtype to the partition | ||||
|   | ||||
		Reference in New Issue
	
	Block a user