@@ -232,7 +232,9 @@ partition_filter_exec(CustomScanState *node)
232
232
ResetExprContext (econtext );
233
233
234
234
/* Replace parent table with a suitable partition */
235
+ old_cxt = MemoryContextSwitchTo (estate -> es_query_cxt );
235
236
estate -> es_result_relation_info = getResultRelInfo (selected_partid , state );
237
+ MemoryContextSwitchTo (old_cxt );
236
238
237
239
return slot ;
238
240
}
@@ -285,24 +287,16 @@ getResultRelInfo(Oid partid, PartitionFilterState *state)
285
287
#define CopyToResultRelInfo (field_name ) \
286
288
( resultRelInfo->field_name = state->savedRelInfo->field_name )
287
289
288
- #define ResizeTriggerField (field_name , field_type ) \
289
- do { \
290
- if (resultRelInfo->field_name) \
291
- pfree(resultRelInfo->field_name); \
292
- resultRelInfo->field_name = (field_type *) \
293
- palloc0(resultRelInfo->ri_TrigDesc->numtriggers * sizeof(field_type)); \
294
- } while (0)
295
-
296
- ResultRelInfoHolder * resultRelInfoHandle ;
290
+ ResultRelInfoHolder * resultRelInfoHolder ;
297
291
bool found ;
298
292
299
- resultRelInfoHandle = hash_search (state -> result_rels_table ,
293
+ resultRelInfoHolder = hash_search (state -> result_rels_table ,
300
294
(const void * ) & partid ,
301
295
HASH_ENTER , & found );
302
296
297
+ /* If not found, create & cache new ResultRelInfo */
303
298
if (!found )
304
299
{
305
- bool grown_up ;
306
300
ResultRelInfo * resultRelInfo = (ResultRelInfo * ) palloc (sizeof (ResultRelInfo ));
307
301
308
302
InitResultRelInfo (resultRelInfo ,
@@ -312,24 +306,6 @@ getResultRelInfo(Oid partid, PartitionFilterState *state)
312
306
313
307
ExecOpenIndices (resultRelInfo , state -> onConflictAction != ONCONFLICT_NONE );
314
308
315
- resultRelInfo -> ri_TrigDesc = append_trigger_descs (resultRelInfo -> ri_TrigDesc ,
316
- state -> savedRelInfo -> ri_TrigDesc ,
317
- & grown_up );
318
- if (grown_up )
319
- {
320
- ResizeTriggerField (ri_TrigFunctions , FmgrInfo );
321
- ResizeTriggerField (ri_TrigWhenExprs , List * );
322
-
323
- if (resultRelInfo -> ri_TrigInstrument )
324
- {
325
- pfree (resultRelInfo -> ri_TrigInstrument );
326
-
327
- resultRelInfo -> ri_TrigInstrument =
328
- InstrAlloc (resultRelInfo -> ri_TrigDesc -> numtriggers ,
329
- state -> css .ss .ps .state -> es_instrument );
330
- }
331
- }
332
-
333
309
/* Copy necessary fields from saved ResultRelInfo */
334
310
CopyToResultRelInfo (ri_WithCheckOptions );
335
311
CopyToResultRelInfo (ri_WithCheckOptionExprs );
@@ -341,14 +317,15 @@ getResultRelInfo(Oid partid, PartitionFilterState *state)
341
317
/* ri_ConstraintExprs will be initialized by ExecRelCheck() */
342
318
resultRelInfo -> ri_ConstraintExprs = NULL ;
343
319
344
- resultRelInfoHandle -> partid = partid ;
345
- resultRelInfoHandle -> resultRelInfo = resultRelInfo ;
346
-
347
320
/* Make 'range table index' point to the parent relation */
348
321
resultRelInfo -> ri_RangeTableIndex = state -> savedRelInfo -> ri_RangeTableIndex ;
322
+
323
+ /* Now fill the ResultRelInfo holder */
324
+ resultRelInfoHolder -> partid = partid ;
325
+ resultRelInfoHolder -> resultRelInfo = resultRelInfo ;
349
326
}
350
327
351
- return resultRelInfoHandle -> resultRelInfo ;
328
+ return resultRelInfoHolder -> resultRelInfo ;
352
329
}
353
330
354
331
/*
0 commit comments