@@ -102,6 +102,7 @@ partition_filter_begin(CustomScanState *node, EState *estate, int eflags)
102102
103103node -> custom_ps = list_make1 (ExecInitNode (state -> subplan ,estate ,eflags ));
104104state -> prel = get_pathman_relation_info (state -> partitioned_table ,NULL );
105+ state -> savedRelInfo = NULL ;
105106
106107memset (result_rels_table_config ,0 ,sizeof (HASHCTL ));
107108result_rels_table_config -> keysize = sizeof (Oid );
@@ -129,6 +130,10 @@ partition_filter_exec(CustomScanState *node)
129130
130131slot = ExecProcNode (child_ps );
131132
133+ /* Save original ResultRelInfo */
134+ if (!state -> savedRelInfo )
135+ state -> savedRelInfo = estate -> es_result_relation_info ;
136+
132137if (!TupIsNull (slot ))
133138{
134139WalkerContext wcxt ;
@@ -140,9 +145,11 @@ partition_filter_exec(CustomScanState *node)
140145AttrNumber attnum = state -> prel -> attnum ;
141146Datum value = slot_getattr (slot ,attnum ,& isnull );
142147
148+ /* Fill const with value ... */
143149state -> temp_const .constvalue = value ;
144150state -> temp_const .constisnull = isnull ;
145151
152+ /* ... and some other important data */
146153CopyToTempConst (consttype ,atttypid );
147154CopyToTempConst (consttypmod ,atttypmod );
148155CopyToTempConst (constcollid ,attcollation );
@@ -162,6 +169,7 @@ partition_filter_exec(CustomScanState *node)
162169else if (nparts == 0 )
163170elog (ERROR ,"PartitionFilter could not select suitable partition" );
164171
172+ /* Replace main table with suitable partition */
165173estate -> es_result_relation_info = getResultRelInfo (parts [0 ],state );
166174
167175return slot ;
@@ -209,6 +217,9 @@ partition_filter_explain(CustomScanState *node, List *ancestors, ExplainState *e
209217static ResultRelInfo *
210218getResultRelInfo (Oid partid ,PartitionFilterState * state )
211219{
220+ #define CopyToResultRelInfo (field_name ) \
221+ ( resultRelInfo->field_name = state->savedRelInfo->field_name )
222+
212223ResultRelInfoHandle * resultRelInfoHandle ;
213224bool found ;
214225
@@ -226,6 +237,17 @@ getResultRelInfo(Oid partid, PartitionFilterState *state)
226237
227238ExecOpenIndices (resultRelInfo ,state -> onConflictAction != ONCONFLICT_NONE );
228239
240+ /* Copy necessary fields from saved ResultRelInfo */
241+ CopyToResultRelInfo (ri_WithCheckOptions );
242+ CopyToResultRelInfo (ri_WithCheckOptionExprs );
243+ CopyToResultRelInfo (ri_junkFilter );
244+ CopyToResultRelInfo (ri_projectReturning );
245+ CopyToResultRelInfo (ri_onConflictSetProj );
246+ CopyToResultRelInfo (ri_onConflictSetWhere );
247+
248+ /* ri_ConstraintExprs will be initialized by ExecRelCheck() */
249+ resultRelInfo -> ri_ConstraintExprs = NULL ;
250+
229251resultRelInfoHandle -> partid = partid ;
230252resultRelInfoHandle -> resultRelInfo = resultRelInfo ;
231253}