@@ -102,6 +102,7 @@ partition_filter_begin(CustomScanState *node, EState *estate, int eflags)
102
102
103
103
node -> custom_ps = list_make1 (ExecInitNode (state -> subplan , estate , eflags ));
104
104
state -> prel = get_pathman_relation_info (state -> partitioned_table , NULL );
105
+ state -> savedRelInfo = NULL ;
105
106
106
107
memset (result_rels_table_config , 0 , sizeof (HASHCTL ));
107
108
result_rels_table_config -> keysize = sizeof (Oid );
@@ -129,6 +130,10 @@ partition_filter_exec(CustomScanState *node)
129
130
130
131
slot = ExecProcNode (child_ps );
131
132
133
+ /* Save original ResultRelInfo */
134
+ if (!state -> savedRelInfo )
135
+ state -> savedRelInfo = estate -> es_result_relation_info ;
136
+
132
137
if (!TupIsNull (slot ))
133
138
{
134
139
WalkerContext wcxt ;
@@ -140,9 +145,11 @@ partition_filter_exec(CustomScanState *node)
140
145
AttrNumber attnum = state -> prel -> attnum ;
141
146
Datum value = slot_getattr (slot , attnum , & isnull );
142
147
148
+ /* Fill const with value ... */
143
149
state -> temp_const .constvalue = value ;
144
150
state -> temp_const .constisnull = isnull ;
145
151
152
+ /* ... and some other important data */
146
153
CopyToTempConst (consttype , atttypid );
147
154
CopyToTempConst (consttypmod , atttypmod );
148
155
CopyToTempConst (constcollid , attcollation );
@@ -162,6 +169,7 @@ partition_filter_exec(CustomScanState *node)
162
169
else if (nparts == 0 )
163
170
elog (ERROR , "PartitionFilter could not select suitable partition" );
164
171
172
+ /* Replace main table with suitable partition */
165
173
estate -> es_result_relation_info = getResultRelInfo (parts [0 ], state );
166
174
167
175
return slot ;
@@ -209,6 +217,9 @@ partition_filter_explain(CustomScanState *node, List *ancestors, ExplainState *e
209
217
static ResultRelInfo *
210
218
getResultRelInfo (Oid partid , PartitionFilterState * state )
211
219
{
220
+ #define CopyToResultRelInfo (field_name ) \
221
+ ( resultRelInfo->field_name = state->savedRelInfo->field_name )
222
+
212
223
ResultRelInfoHandle * resultRelInfoHandle ;
213
224
bool found ;
214
225
@@ -226,6 +237,17 @@ getResultRelInfo(Oid partid, PartitionFilterState *state)
226
237
227
238
ExecOpenIndices (resultRelInfo , state -> onConflictAction != ONCONFLICT_NONE );
228
239
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
+
229
251
resultRelInfoHandle -> partid = partid ;
230
252
resultRelInfoHandle -> resultRelInfo = resultRelInfo ;
231
253
}
0 commit comments