Re: Allow progress tracking of sub-commands

From: Antonin Houska <ah(at)cybertec(dot)at>
To: Manu <manuelreyesbravo(at)gmail(dot)com>
Cc: Alberto Piai <alberto(dot)piai(at)gmail(dot)com>, Rahila Syed <rahilasyed90(at)gmail(dot)com>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, alvherre(at)kurilemu(dot)de, pgsql-hackers(at)lists(dot)postgresql(dot)org, bharath(dot)rupireddyforpostgres(at)gmail(dot)com, mihailnikalayeu(at)gmail(dot)com, adam8157(at)gmail(dot)com
Subject: Re: Allow progress tracking of sub-commands
Date: 2026-11-26 17:01:46
Message-ID: 115749.1795712506@chrudos
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Manu <manuelreyesbravo(at)gmail(dot)com> wrote:

> Thanks for v03. Both problems I reported are gone: a failed nested
> COPY no longer leaves a row behind or leaks memory, and REPACK keeps
> its row while it rebuilds the indexes.
>
> I did find a few more cases where a row gets stuck or lost.
>
> On Mon, Nov 23, 2026 at 7:29 PM Antonin Houska <ah(at)cybertec(dot)at> wrote:
> > Thanks for finding this problem. v03 should handle errors in file_fdw
> > correctly.
>
> It does with one scan, but not when two file_fdw scans are running
> and one of them fails. With ft_bad being a file_fdw table whose last
> line is bad:
>
> SELECT (SELECT count(*) FROM ft_bad) + (SELECT count(*) FROM ft);
>
> After this error the session reports no progress for anything that
> follows, and with asserts enabled the next commit fails the Assert in
> xact_callback(). The callback only undoes one of the two scans, so
> active_nodes stays at 1.

Should work in v04 [1].

> Two related ones: if a COPY fails while one of its triggers is inside
> a file_fdw scan, the COPY's row is never removed, because the abort
> ends progress before the callback turns tracking back on. And a
> two-scan query that succeeds inside a COPY trigger removes the outer
> COPY's row, because the scan resumes tracking before EndCopyFrom().
>
> > Likewise, error handling fixed in v03.
>
> The case that still breaks here is a cursor closed in a
> subtransaction:
>
> BEGIN; DECLARE c CURSOR FOR SELECT * FROM ft; FETCH c;
> SAVEPOINT s; CLOSE c; RELEASE s; COMMIT;
>
> The cursor's COPY row is still there after the COMMIT, survives later
> errors, and hides the next CREATE INDEX. As far as I can tell, CLOSE
> sees progress_depth 0 in the subtransaction, and nothing carries the
> depth over when the subtransaction commits.

This should also work in v04.

Thanks for finding these non-trivial problems.

[1] https://www.postgresql.org/message-id/115231.1795710799@chrudos

--
Antonin Houska
Web: https://www.cybertec-postgresql.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Álvaro Herrera 2026-11-26 17:04:09 [dave.sharpe@datastone.ca: [PATCH] doc: corrections for commands that are not MVCC-safe (REPACK CONCURRENTLY, pg_dump, REFRESH MATERIALIZED VIEW)]
Previous Message Antonin Houska 2026-11-26 16:52:58 Re: Allow progress tracking of sub-commands