@@ -620,19 +620,28 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
620620 expr_state = ExecInitExpr ((Expr * ) expr , NULL );
621621 }
622622
623+ /* Switch into per tuple memory context */
624+ MemoryContextSwitchTo (GetPerTupleMemoryContext (estate ));
625+
623626 if (!NextCopyFrom (cstate , econtext , values , nulls , & tuple_oid ))
624627 break ;
625628
626- /* And now we can form the input tuple. */
629+ /* We can form the input tuple. */
627630 tuple = heap_form_tuple (tupDesc , values , nulls );
628631
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+
629641 /* Place tuple in tuple slot --- but slot shouldn't free it */
630642 slot = myslot ;
631643 ExecStoreTuple (tuple , slot , InvalidBuffer , false);
632644
633- /* Switch into per tuple memory context */
634- MemoryContextSwitchTo (GetPerTupleMemoryContext (estate ));
635-
636645 /* Execute expression */
637646 tmp_slot = econtext -> ecxt_scantuple ;
638647 econtext -> ecxt_scantuple = slot ;
@@ -663,15 +672,6 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
663672 heap_freetuple (tuple_old );
664673 }
665674
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-
675675 /* Triggers and stuff need to be invoked in query context. */
676676 MemoryContextSwitchTo (oldcontext );
677677
0 commit comments