| 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-27 10:48:54 |
| Message-ID: | 86206.1795776534@chrudos |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Manu <manuelreyesbravo(at)gmail(dot)com> wrote:
> Only case 2 from my last mail, which master has too, so it is not
> a regression. In plain SQL, after "seq 1000 > /tmp/n.txt" and
> "seq 3 > /tmp/three.txt":
>
> CREATE EXTENSION file_fdw;
> CREATE SERVER f FOREIGN DATA WRAPPER file_fdw;
> CREATE FOREIGN TABLE ft (a int) SERVER f
> OPTIONS (filename '/tmp/n.txt');
> CREATE TABLE t (a int);
> CREATE FUNCTION trg() RETURNS trigger LANGUAGE plpgsql
> SET enable_hashjoin = off SET enable_nestloop = off AS $$
> BEGIN
> IF NEW.a = 2 THEN
> -- two file_fdw scans in one query (a merge join)
> PERFORM count(*) FROM ft x JOIN ft y USING (a);
> END IF;
> PERFORM pg_stat_clear_snapshot();
> RAISE NOTICE 'row %: % row(s) in pg_stat_progress_copy',
> NEW.a, (SELECT count(*) FROM pg_stat_progress_copy
> WHERE pid = pg_backend_pid());
> RETURN NEW;
> END $$;
> CREATE TRIGGER tr BEFORE INSERT ON t
> FOR EACH ROW EXECUTE FUNCTION trg();
> COPY t FROM '/tmp/three.txt';
>
> On both v05 and master:
>
> NOTICE: row 1: 1 row(s) in pg_stat_progress_copy
> NOTICE: row 2: 0 row(s) in pg_stat_progress_copy
> NOTICE: row 3: 0 row(s) in pg_stat_progress_copy
>
> The COPY's row is gone from the moment the two-scan query in its
> trigger finishes until the end of the COPY. I don't think it needs
> to block v05.
v06 fixes this too (hopefully it doesn't break the previous fixes). Attached
is also the change between v05 and v06 separate.
The problem is that only the COPY FROM is executed by file_fdw, so file_fdw
alone cannot guard against this case. v06 introduces a concept of a "dummy
command" - see the is_dummy field in PgBackendProgress.
0002 is still needed because file_fdw can run multiple COPY FROM commands at
the same time.
Thanks again for thorough testing!
--
Antonin Houska
Web: https://www.cybertec-postgresql.com
| Attachment | Content-Type | Size |
|---|---|---|
| v06-0001-Allow-progress-tracking-of-sub-commands.patch | application/mbox | 50.0 KB |
| v06-0002-Do-not-report-progress-of-two-or-more-COPY-commands-.patch | application/mbox | 5.6 KB |
| progress_dummy_command.diff.nocfbot | text/x-diff | 4.9 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Dave Sharpe | 2026-11-27 10:51:20 | [PATCH] doc: corrections for commands that are not MVCC-safe (REPACK CONCURRENTLY, pg_dump, REFRESH MATERIALIZED VIEW) |
| Previous Message | Jim Jones | 2026-11-27 10:34:51 | Re: OOM kill in xmlelement() with large arrays |