mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Handle INSERT .. ON CONFLICT with partitioned tables
Commit eb7ed3f306 enabled unique constraints on partitioned tables,
but one thing that was not working properly is INSERT/ON CONFLICT.
This commit introduces a new node keeps state related to the ON CONFLICT
clause per partition, and fills it when that partition is about to be
used for tuple routing.
Author: Amit Langote, Álvaro Herrera
Reviewed-by: Etsuro Fujita, Pavan Deolasee
Discussion: https://postgr.es/m/20180228004602.cwdyralmg5ejdqkq@alvherre.pgsql
			
			
This commit is contained in:
		@@ -362,6 +362,20 @@ typedef struct JunkFilter
 | 
			
		||||
	AttrNumber	jf_junkAttNo;
 | 
			
		||||
} JunkFilter;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * OnConflictSetState
 | 
			
		||||
 *
 | 
			
		||||
 * Executor state of an ON CONFLICT DO UPDATE operation.
 | 
			
		||||
 */
 | 
			
		||||
typedef struct OnConflictSetState
 | 
			
		||||
{
 | 
			
		||||
	NodeTag		type;
 | 
			
		||||
 | 
			
		||||
	ProjectionInfo *oc_ProjInfo;	/* for ON CONFLICT DO UPDATE SET */
 | 
			
		||||
	TupleDesc	oc_ProjTupdesc; /* TupleDesc for the above projection */
 | 
			
		||||
	ExprState  *oc_WhereClause; /* state for the WHERE clause */
 | 
			
		||||
} OnConflictSetState;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * ResultRelInfo
 | 
			
		||||
 *
 | 
			
		||||
@@ -424,11 +438,11 @@ typedef struct ResultRelInfo
 | 
			
		||||
	/* for computing a RETURNING list */
 | 
			
		||||
	ProjectionInfo *ri_projectReturning;
 | 
			
		||||
 | 
			
		||||
	/* for computing ON CONFLICT DO UPDATE SET */
 | 
			
		||||
	ProjectionInfo *ri_onConflictSetProj;
 | 
			
		||||
	/* list of arbiter indexes to use to check conflicts */
 | 
			
		||||
	List	   *ri_onConflictArbiterIndexes;
 | 
			
		||||
 | 
			
		||||
	/* list of ON CONFLICT DO UPDATE exprs (qual) */
 | 
			
		||||
	ExprState  *ri_onConflictSetWhere;
 | 
			
		||||
	/* ON CONFLICT evaluation state */
 | 
			
		||||
	OnConflictSetState *ri_onConflict;
 | 
			
		||||
 | 
			
		||||
	/* partition check expression */
 | 
			
		||||
	List	   *ri_PartitionCheck;
 | 
			
		||||
 
 | 
			
		||||
@@ -34,6 +34,7 @@ typedef enum NodeTag
 | 
			
		||||
	T_ExprContext,
 | 
			
		||||
	T_ProjectionInfo,
 | 
			
		||||
	T_JunkFilter,
 | 
			
		||||
	T_OnConflictSetState,
 | 
			
		||||
	T_ResultRelInfo,
 | 
			
		||||
	T_EState,
 | 
			
		||||
	T_TupleTableSlot,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user