Hi Jian

On 12/05/2026 10:15, jian he wrote:
> Attached v3 fix this issue.

== closing relation too early ==

In noticed that in BeginCopyFrom() you open cstate->conflictRel and
close it after the CopyFromConflictTableCheck() call

cstate->conflictRel = table_open(conflictRelid, NoLock);
CopyFromConflictTableCheck(cstate);
table_close(cstate->conflictRel, NoLock);

But if we take a look at DoCopy(), the function CopyFrom() is called
immediately after a BeginCopyFrom() call, which now references to a
closed relation in cstate->conflictRel. I guess we should close the
relation in EndCopyFrom().

== redundant if blocks ==

These two if (cstate->opts.on_conflict == ONCONFLICT_TABLE) could be merged:

if (cstate->opts.on_conflict == ONCONFLICT_TABLE)
{
  node->onConflictAction = ONCONFLICT_NOTHING;
  node->canSetTag = true;
}

Assert(cstate->rel);
Assert(list_length(cstate->range_table) == 1);

if (cstate->opts.on_error != COPY_ON_ERROR_STOP)
  Assert(cstate->escontext);

if (cstate->opts.on_conflict == ONCONFLICT_TABLE)
  conflictslot = ExecInitExtraTupleSlot(estate,
    RelationGetDescr(cstate->conflictRel),
    &TTSOpsVirtual);

== comments ==
ON_CONFLCT > ON_CONFLICT
unqiue > unique

IIUC, it should be here (copy.h) "on conflict" instead of "on error", right?

char       *on_conflictRel; /* on error, save error info to the table,
                                                                 * table name */

Thanks!
Best, Jim



Reply via email to