@@ -620,19 +620,28 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
620
620
expr_state = ExecInitExpr ((Expr * ) expr , NULL );
621
621
}
622
622
623
+ /* Switch into per tuple memory context */
624
+ MemoryContextSwitchTo (GetPerTupleMemoryContext (estate ));
625
+
623
626
if (!NextCopyFrom (cstate , econtext , values , nulls , & tuple_oid ))
624
627
break ;
625
628
626
- /* And now we can form the input tuple. */
629
+ /* We can form the input tuple. */
627
630
tuple = heap_form_tuple (tupDesc , values , nulls );
628
631
632
+ if (tuple_oid != InvalidOid )
633
+ HeapTupleSetOid (tuple , tuple_oid );
634
+
635
+ /*
636
+ * Constraints might reference the tableoid column, so initialize
637
+ * t_tableOid before evaluating them.
638
+ */
639
+ tuple -> t_tableOid = RelationGetRelid (child_result_rel -> ri_RelationDesc );
640
+
629
641
/* Place tuple in tuple slot --- but slot shouldn't free it */
630
642
slot = myslot ;
631
643
ExecStoreTuple (tuple , slot , InvalidBuffer , false);
632
644
633
- /* Switch into per tuple memory context */
634
- MemoryContextSwitchTo (GetPerTupleMemoryContext (estate ));
635
-
636
645
/* Execute expression */
637
646
tmp_slot = econtext -> ecxt_scantuple ;
638
647
econtext -> ecxt_scantuple = slot ;
@@ -663,15 +672,6 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
663
672
heap_freetuple (tuple_old );
664
673
}
665
674
666
- if (tuple_oid != InvalidOid )
667
- HeapTupleSetOid (tuple , tuple_oid );
668
-
669
- /*
670
- * Constraints might reference the tableoid column, so initialize
671
- * t_tableOid before evaluating them.
672
- */
673
- tuple -> t_tableOid = RelationGetRelid (child_result_rel -> ri_RelationDesc );
674
-
675
675
/* Triggers and stuff need to be invoked in query context. */
676
676
MemoryContextSwitchTo (oldcontext );
677
677
0 commit comments