| From: | Manu <manuelreyesbravo(at)gmail(dot)com> |
|---|---|
| To: | Antonin Houska <ah(at)cybertec(dot)at> |
| 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-30 22:53:26 |
| Message-ID: | 179607920687.241315.10339053263011417737@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Antonin,
v07 fixes case 2: the script from my last mail now gives 1, 1 and 1
rows, and the earlier cases still pass. But in 0002, nodes is
counted when the plan is made and nodes_ended when the scans end, and
the two counts can drift apart. When they do, progress reporting
stays off for the rest of the session, CREATE INDEX included. Tested
on master 9ebc9a458c3.
> Disabling the reporting in file_fdw (if the number of nodes is greater than
> one) seems cleaner. If file_fdw relied on the fact that the 2nd node will be
> treated as dummy, the 1st one would still appear in the pg_stat_progress_copy
> view, and it wouldn't receive updates.
Agreed.
The cases below use ft and ft2, file_fdw tables over seq 1000, and
CREATE VIEW me AS SELECT count(*) AS copy_rows
FROM pg_stat_progress_copy WHERE pid = pg_backend_pid();
SELECT a, (SELECT copy_rows FROM me) FROM ft LIMIT 1;
where the SELECT should show copy_rows = 1. Each case starts in a
new session; the two-scan ones use a merge join (hash and nested
loop joins off).
1. An error outside the scan, with a single file_fdw table:
SELECT a FROM ft WHERE 1/(a - a) = 1;
After it, the SELECT above gives 0 every time; v06 gave 0 once and
then 1. The PG_TRY covers only fileIterateForeignScan(), so an
error in a qual, a unique violation in INSERT ... SELECT FROM ft,
a statement_timeout, or a failing BeginCopyFrom() in the second
node leaves the counters unbalanced.
2. EXPLAIN without ANALYZE of a two-scan query has the same effect.
For a NULL fdw_state, fileEndForeignScan() resumes without counting
the node. Anyone who looks at the plan before testing will find
reporting off.
3. A cached plan does not go through fileGetForeignPlan(), so the
second EXECUTE of a prepared two-scan query reports as it would
without 0002. The same happens from PL/pgSQL and with
plan_cache_mode = force_generic_plan.
4. New in v07, and without an error, a row is left behind:
CREATE FUNCTION lk(int) RETURNS int LANGUAGE plpgsql AS
$$ BEGIN RETURN (SELECT count(*) FROM ft2 WHERE a = $1); END $$;
SELECT a, lk(a) FROM ft LIMIT 3;
With this session idle, another one still sees ft's COPY FROM in
pg_stat_progress_copy. Each custom plan made for the query in lk()
adds to nodes, so reporting is switched off while ft's COPY runs,
and its pgstat_progress_end_command() then does nothing. v06
leaves no row.
ROLLBACK with a cursor on a two-scan query still open also leaves
reporting off, as in v06, and so does initial pruning of file_fdw
partitions in a generic plan, which is a rarer case.
One point from my mail to Alberto on 25-11 is still open in v07, and
it is not only about readers. With another session holding an
uncommitted INSERT, REINDEX INDEX CONCURRENTLY shows command NULL and
index_relid 0 while it waits for writers, where master shows REINDEX
CONCURRENTLY and the index. The waits in phases 2, 3 and 5 start a
new command and set only the phase. Any table with writes waits
there. Alberto's suggestion, updating the phase of the current
command, would avoid it.
Small things in 0002: "two more" should be "two or more" in the
commit message, "regardless EXPLAIN" and "regardless _suspended" need
an "of", the backend_status.h include is out of order, and there is no
test yet; the cases above could make one for file_fdw.
Regards,
Manu
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Sami Imseih | 2026-11-30 22:59:21 | Re: pgstat: Flush some statistics within running transactions, take 2 |
| Previous Message | Heikki Linnakangas | 2026-11-30 22:46:46 | Re: Disable startup progress timeout during standby WAL replay |