Re: on_error table, saving error info to a table

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: solaimurugan vellaipandiyan <drsolaimurugan(dot)v(at)gmail(dot)com>
Cc: Nishant Sharma <nishant(dot)sharma(at)enterprisedb(dot)com>, Kirill Reshke <reshkekirill(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: on_error table, saving error info to a table
Date: 2026-05-11 02:06:23
Message-ID: CACJufxGBmz=W63R0ufSCEauokapWJg=YrvvcyjD+8ia1N5B-DQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, May 6, 2026 at 4:08 PM jian he <jian(dot)universality(at)gmail(dot)com> wrote:
>
> v9-0002: Introduce a (ModifyTableContext *) field in CopyFromStateData.
> Initialize all useful subordinate structures, including such as
> ModifyTableState, EState, and ModifyTableState->ResultRelInfo. Set
> cstate->escontext->details_wanted to true to ensure that all input conversion
> error metadata is captured in cstate->escontext. Use this metadata to construct
> a TupleTableSlot, and then delegate the remaining processing to ExecInsert.
>
> Before calling ExecInsert() to insert error metadata into the ERROR_TABLE, we
> must first populate a ModifyTableState, similar to how it is done in
> ExecInitModifyTable.
>
> By comparing side-by-side with ExecInitModifyTable, it is ok to populate the
> necessary information for the ERROR_TABLE using the following functions:
> ExecInitRangeTable, ExecInitResultRelation, ExecOpenIndices, and
> CheckValidResultRel.
> This will allow the ERROR_TABLE to safely use ExecInsert().
>

example
CREATE TABLE t(a int);
INSERT INTO t VALUES (1);

Execution flow:
ProcessQuery:
queryDesc = CreateQueryDesc(plan, sourceText,
GetActiveSnapshot(), InvalidSnapshot,
dest, params, queryEnv, 0);

CreateQueryDesc:
qd->snapshot = RegisterSnapshot(snapshot);

standard_ExecutorStart:
estate->es_snapshot = RegisterSnapshot(queryDesc->snapshot);

For COPY FROM, PortalRunUtility -> ProcessUtility ->
standard_ProcessUtility -> DoCopy ensures that an ActiveSnapshot
is available through PortalRunUtility()->PlannedStmtRequiresSnapshot().

Therefore, I think it is OK for the CopyFrom function to register a
active snapshot
(EState->es_snapshot) during constructing the EState, in case snapshot access is
needed later.

EState *estate = CreateExecutorState(); /* for ExecConstraints() */

Add:
estate->es_snapshot =
RegisterSnapshot(GetActiveSnapshot());
estate->es_crosscheck_snapshot =
RegisterSnapshot(InvalidSnapshot);

Similarly, it would be better let
CopyFromStateData->ModifyTableContext->EState->es_snapshot
also Register the current ActiveSnapshot.
Just in case the ExecInsert function needs to use it.

In the attached v10, the code flow for inserting content into the error-saving
table involves constructing an EState, while the population and release of its
subfields align more closely with how ExecutorStart, ExecutorFinish,
and ExecutorEnd deal with EState.

--
jian
https://www.enterprisedb.com/

Attachment Content-Type Size
v10-0001-export-ExecInsert.patch text/x-patch 4.8 KB
v10-0002-COPY-FROM-on_error-table-error_table-errtbl.patch text/x-patch 53.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2026-05-11 02:08:36 Re: Missing jsonb_ ... functions on DOCs
Previous Message Michael Paquier 2026-05-11 01:58:28 Re: [PATCH] Fix ProcKill lock-group vs procLatch recycle race