mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Allow UPDATE to move rows between partitions.
When an UPDATE causes a row to no longer match the partition constraint, try to move it to a different partition where it does match the partition constraint. In essence, the UPDATE is split into a DELETE from the old partition and an INSERT into the new one. This can lead to surprising behavior in concurrency scenarios because EvalPlanQual rechecks won't work as they normally did; the known problems are documented. (There is a pending patch to improve the situation further, but it needs more review.) Amit Khandekar, reviewed and tested by Amit Langote, David Rowley, Rajkumar Raghuwanshi, Dilip Kumar, Amul Sul, Thomas Munro, Álvaro Herrera, Amit Kapila, and me. A few final revisions by me. Discussion: http://postgr.es/m/CAJ3gD9do9o2ccQ7j7+tSgiE1REY65XRiMb=yJO3u3QhyP8EEPQ@mail.gmail.com
This commit is contained in:
		@@ -992,8 +992,8 @@ typedef struct ModifyTableState
 | 
			
		||||
	/* controls transition table population for specified operation */
 | 
			
		||||
	struct TransitionCaptureState *mt_oc_transition_capture;
 | 
			
		||||
	/* controls transition table population for INSERT...ON CONFLICT UPDATE */
 | 
			
		||||
	TupleConversionMap **mt_transition_tupconv_maps;
 | 
			
		||||
	/* Per plan/partition tuple conversion */
 | 
			
		||||
	TupleConversionMap **mt_per_subplan_tupconv_maps;
 | 
			
		||||
	/* Per plan map for tuple conversion from child to root */
 | 
			
		||||
} ModifyTableState;
 | 
			
		||||
 | 
			
		||||
/* ----------------
 | 
			
		||||
 
 | 
			
		||||
@@ -219,6 +219,7 @@ typedef struct ModifyTable
 | 
			
		||||
	Index		nominalRelation;	/* Parent RT index for use of EXPLAIN */
 | 
			
		||||
	/* RT indexes of non-leaf tables in a partition tree */
 | 
			
		||||
	List	   *partitioned_rels;
 | 
			
		||||
	bool		partColsUpdated;	/* some part key in hierarchy updated */
 | 
			
		||||
	List	   *resultRelations;	/* integer list of RT indexes */
 | 
			
		||||
	int			resultRelIndex; /* index of first resultRel in plan's list */
 | 
			
		||||
	int			rootResultRelIndex; /* index of the partitioned table root */
 | 
			
		||||
 
 | 
			
		||||
@@ -1674,6 +1674,7 @@ typedef struct ModifyTablePath
 | 
			
		||||
	Index		nominalRelation;	/* Parent RT index for use of EXPLAIN */
 | 
			
		||||
	/* RT indexes of non-leaf tables in a partition tree */
 | 
			
		||||
	List	   *partitioned_rels;
 | 
			
		||||
	bool		partColsUpdated;	/* some part key in hierarchy updated */
 | 
			
		||||
	List	   *resultRelations;	/* integer list of RT indexes */
 | 
			
		||||
	List	   *subpaths;		/* Path(s) producing source data */
 | 
			
		||||
	List	   *subroots;		/* per-target-table PlannerInfos */
 | 
			
		||||
@@ -2124,6 +2125,8 @@ typedef struct PartitionedChildRelInfo
 | 
			
		||||
 | 
			
		||||
	Index		parent_relid;
 | 
			
		||||
	List	   *child_rels;
 | 
			
		||||
	bool		part_cols_updated;	/* is the partition key of any of
 | 
			
		||||
									 * the partitioned tables updated? */
 | 
			
		||||
} PartitionedChildRelInfo;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user