@@ -316,6 +316,10 @@ fill_tuple_defaults(PGLogicalRelation *rel, ExprContext *econtext,
316
316
int * defmap ;
317
317
ExprState * * defexprs ;
318
318
319
+ /* We got all the data via replication, no need to evaluate anything. */
320
+ if (num_phys_attrs == rel -> natts )
321
+ return ;
322
+
319
323
defmap = (int * ) palloc (num_phys_attrs * sizeof (int ));
320
324
defexprs = (ExprState * * ) palloc (num_phys_attrs * sizeof (ExprState * ));
321
325
@@ -357,11 +361,13 @@ handle_insert(StringInfo s)
357
361
PGLogicalTupleData newtup ;
358
362
PGLogicalRelation * rel ;
359
363
EState * estate ;
364
+ ExprContext * econtext ;
360
365
Oid conflicts ;
361
366
TupleTableSlot * localslot ,
362
367
* applyslot ;
363
368
HeapTuple remotetuple ;
364
369
HeapTuple applytuple ;
370
+ MemoryContext oldcontext = CurrentMemoryContext ;
365
371
PGLogicalConflictResolution resolution ;
366
372
bool started_tx = ensure_transaction ();
367
373
@@ -376,7 +382,11 @@ handle_insert(StringInfo s)
376
382
377
383
/* Initialize the executor state. */
378
384
estate = create_estate_for_relation (rel -> rel );
379
- fill_tuple_defaults (rel , GetPerTupleExprContext (estate ), & newtup );
385
+ econtext = GetPerTupleExprContext (estate );
386
+
387
+ MemoryContextSwitchTo (GetPerTupleMemoryContext (estate ));
388
+ fill_tuple_defaults (rel , econtext , & newtup );
389
+
380
390
localslot = ExecInitExtraTupleSlot (estate );
381
391
applyslot = ExecInitExtraTupleSlot (estate );
382
392
ExecSetSlotDescriptor (localslot , RelationGetDescr (rel -> rel ));
@@ -392,6 +402,7 @@ handle_insert(StringInfo s)
392
402
393
403
remotetuple = heap_form_tuple (RelationGetDescr (rel -> rel ),
394
404
newtup .values , newtup .nulls );
405
+ MemoryContextSwitchTo (oldcontext );
395
406
396
407
if (OidIsValid (conflicts ))
397
408
{
@@ -483,6 +494,8 @@ handle_update(StringInfo s)
483
494
PGLogicalTupleData * searchtup ;
484
495
PGLogicalRelation * rel ;
485
496
EState * estate ;
497
+ ExprContext * econtext ;
498
+ MemoryContext oldcontext = CurrentMemoryContext ;
486
499
bool found ;
487
500
bool hasoldtup ;
488
501
TupleTableSlot * localslot ,
@@ -503,7 +516,11 @@ handle_update(StringInfo s)
503
516
504
517
/* Initialize the executor state. */
505
518
estate = create_estate_for_relation (rel -> rel );
506
- fill_tuple_defaults (rel , GetPerTupleExprContext (estate ), & newtup );
519
+ econtext = GetPerTupleExprContext (estate );
520
+
521
+ MemoryContextSwitchTo (GetPerTupleMemoryContext (estate ));
522
+ fill_tuple_defaults (rel , econtext , & newtup );
523
+
507
524
localslot = ExecInitExtraTupleSlot (estate );
508
525
applyslot = ExecInitExtraTupleSlot (estate );
509
526
ExecSetSlotDescriptor (localslot , RelationGetDescr (rel -> rel ));
@@ -517,6 +534,8 @@ handle_update(StringInfo s)
517
534
remotetuple = heap_form_tuple (RelationGetDescr (rel -> rel ),
518
535
newtup .values , newtup .nulls );
519
536
537
+ MemoryContextSwitchTo (oldcontext );
538
+
520
539
/*
521
540
* Tuple found.
522
541
*
0 commit comments